objective c - Sort Array of NSString By Custom Method -
how go sorting array of nsstring objects custom method. example have method
-(int)calculatevalue:(nsstring *)astring
i sort array descending order based on returned value method. example have array
nsmutablearray *array = [[nsmutablearray alloc] initwithobjects:@"apple", @"bee", @"super", nil];
now if call calculatevalue each of strings might return values such as.
"apple" = 15, "bee" = 21, , "super" = 3. i'm trying sort array based on returned value each nsstring calculatevalue method. sorted array like
[bee, apple, super]
see -sortedarrayusingselector:. you'll pass in selector @selector(mycomparisonmethod:)
. comparison method should return nscomparisonresult nsorderedascending, nsordereddescending, or nsorderedsame.
Comments
Post a Comment