I'm trying to sort an array, from a previous post I was pointed to an answer in this thread, Sorting an array of doubles or CLLocationDistance values on the iPhone
Based of this my code is as follows:
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 'objc_exception_throw'.
What am I doing wrong, I must be leaving out some functionality.
Regards, Stephen
If these are NSManagedObjects, you want valueForKey:, not objectForKey:
Like this...
int v1 = [[num1 valueForKey:@"waypoint_order"] intValue];
Hope that helps.
check num1 dictionary. is it autorelease or u release it somewhere in program.
or check value return by Dictionary may be it returning nil;
see linkArray object .at the time of creating u assigned last Value to nil or not . eg:
[[NSArray alloc]initWithObject:object1,object2,object3,nil];
精彩评论