用NSFetchRequest获取NSArray,里面都是托管对象。如果上下文里没有数据,就会从持久化存储区里获取。
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Item"]; NSArray *itemObjects = [_coreDataHelper.context executeFetchRequest:request error:nil]; for (Item *item in itemObjects) { NSLog(@"item name = %@", item.name); }