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);
    }

 

posted on 2015-11-04 06:56  大木哥  阅读(367)  评论(0编辑  收藏  举报

导航