NSArray *sortedArray =[listArray sortedArrayUsingFunction:intSort context:nil];
NSInteger intSort(id num1, id num2, void *dummy)
{
int v1 = [[num1 objectForKey:@"waypoint_order"] intValue];
int v2 = [[num2 objectForKey:@"waypoint_order"] intValue];
if (v1 < v2)
return NSOrderedAscending;
else if (v1 > v2)
return NSOrderedDescending;
else
return NSOrderedSame;
}
But its crashing on line int v1 = [[num1 objectForKey:@"waypoint_order"] intValue]; with '-[NSManagedObject objectForKey:]: unrecognized selector sent to instance 0x7a6b7f0'.
What am I doing wrong, I must be leaving out some functionality.
Personally, I'm very wary of manipulating NSManagedObjects outside of CoreData's control. If I wanted a sorted array in this case, I would use a sort descriptor as part of the fetch request itself to sort the data. Would be neater, probably faster and avoids manually messing with NSManagedObjects.
Personally, I'm very wary of manipulating NSManagedObjects outside of CoreData's control. If I wanted a sorted array in this case, I would use a sort descriptor as part of the fetch request itself to sort the data. Would be neater, probably faster and avoids manually messing with NSManagedObjects.
Thanks, I did try that but the values in CoreData are all strings. So this was causing a problem i.e. the results were 1,10,11,12.....2,20,21,22....etc.
Is there a way to sort a string as an integer via the NSFetchRequest.