2.13.1. 对结果排序(Core Data 应用程序实践指南)
传递NSSortDescriptor给NSFetchRequest进行排序。示例如下,修改demo方法:
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]; NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Item"]; [request setSortDescriptors:[NSArray arrayWithObject:sort]]; NSArray *itemObjects = [_coreDataHelper.context executeFetchRequest:request error:nil]; for (Item *item in itemObjects) { NSLog(@"item name = %@", item.name); }