ios - Sort NSMutableArray with custom objects -


i have ios app nsmutablearray contains many rows worth of data (split 3 segments) - shown below:

[pfuser object, stringdata, floatvalue]        .             .          4.3        .             .          5.9        .             .          1.1        .             .          9.32        .             .          0.024 

the above diagram shows how array split , data types stored in array. data types not keys or anything. can't valueforkey.

an example of array looks like:

@[@[userobject, @"hello", @234.1441],   @[userobject, @"sdfsg", @94.33],   @[userobject, @"wrfdo", @24.897] ]; 

so example above can see have arrays in arrays.

i sort array reading 3 segment contains float values.

how can this? have looked online , read lot using nssortdescriptor problem have examples seem use simple strings or array numbers only.

is there way use nssortdescriptor in array custom objects mine?

you can use sortusingcomparator:

[array sortusingcomparator:^(id obj1, id obj2) {     nsarray *arr1 = obj1;     nsarray *arr2 = obj2;     return [arr1[2] compare:arr2[2]]; }]; 

or (thanks rmaddy's suggestion):

[array sortusingcomparator:^(nsarray *arr1, nsarray *arr2) {     return [arr1[2] compare:arr2[2]]; }]; 

if have immutable array, can use sortedarrayusingcomparator:


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -