Iphone 如何对NSMutableArray排序
可能重复:Iphone 如何对NSMutableArray排序,iphone,objective-c,Iphone,Objective C,可能重复: (我认为)在一些基本的问题上有困难 我有一个NSMutable数组,我用“训练”对象填充它。“startDate”方法返回一个NSDate,我想对数组进行排序 NSSortDescriptor*sortByDate行由于未捕获的异常而终止。这里怎么了 NSMutableArray *workouts; workouts = [[[Workout findByCriteria:@"where state = %@ order by pk desc", [NSNumber num
(我认为)在一些基本的问题上有困难 我有一个NSMutable数组,我用“训练”对象填充它。“startDate”方法返回一个NSDate,我想对数组进行排序 NSSortDescriptor*sortByDate行由于未捕获的异常而终止。这里怎么了
NSMutableArray *workouts;
workouts = [[[Workout findByCriteria:@"where state = %@ order by pk desc",
[NSNumber numberWithInt:WorkoutStateComplete]] mutableCopy] autorelease];
NSSortDescriptor *sortByDate = [NSSortDescriptor
sortDescriptorWithKey:@"startDate" ascending:NO];
[workouts sortUsingDescriptors:[NSArray arrayWithObject:sortByDate]];
确保训练数组中的所有对象都未将
startDate
设置为nil或return nil。还要确保数组中的所有对象都响应startDate
选择器。引发了什么异常?Kenny-我查看了很多链接,但没有看到这个链接。离我足够近,让我直了。谢谢。杰里米-从来没有告诉过我更多关于例外的信息。看看这个