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

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -