0

I have a NSArray with core data entities called:

"Struct"

thy have an attribute called "value" that can be a double

Struct *struct = [array objectAtIndex:0];
double val = [struct value];

I have to sorting this array by this value but I don't understand what's the way to do it, because I have not a key to access to the object.

Do you have any suggests?

David
  • 15,894
  • 22
  • 55
  • 66
cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241

1 Answers1

0
NSMutableArray *sortedArray;
sortedArray = [array sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
    NSNumber *s1 = @([(Struct *)a value]);
    NSNumber *s2 = @([(Struct *)b value]);
    return [s1 compare:s2];
}];
Matteo Gobbi
  • 17,697
  • 3
  • 27
  • 41