[英]Sort core data nsarray numeric
I've a problem sorting an nsarray. 我在排序nsarray时遇到问题。 The nsarray is filled with core data:
nsarray充满了核心数据:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"ReactionInfo" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSError *error;
self.scoreInfos_arr = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
for (ReactionInfo *info in self.scoreInfos_arr) {
debug(@"%@ - %f",info.player,info.score);
}
U see that I get the player name and the score. 你看我得到了球员的名字和得分。 My target is, to show the scores in a table view, but of course they should be sort numeric.
我的目标是在表格视图中显示分数,但是当然它们应该是数字排序。
I didn't find a solution on how to sort this NSArray (self.scoreInfos_arr is it) 我没有找到关于如何对这个NSArray进行排序的解决方案(是self.scoreInfos_arr)
I hope somebody can help me. 我希望有人能帮助我。
Use a NSSortDescriptor 使用NSSortDescriptor
[fetchRequest setSortDescriptors: [NSArray arrayWithObject:
[[[NSSortDescriptor alloc] initWithKey:@"score"
ascending:YES] autorelease]]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.