我无法理解 NSManagedObjectContextConcurrencyType 的文档。在以下情况下我会使用哪种类型,为什么?
- (void)viewDidLoad
{
self.managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:???];
[self loadRecordsFromCoreData];
}
- (void)loadRecordsFromCoreData {
[self.managedObjectContext performBlockAndWait:^{
//[self.managedObjectContext reset]; //do I need to do this?
NSError *error = nil;
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Item"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"display == YES"];
[request setPredicate:predicate];
[request setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"order" ascending:YES]]];
self.items = nil;
self.items = [self.managedObjectContext executeFetchRequest:request error:&error];
}];
[self displayItems];
}
-displayItems 将根据 self.items 数组中对象的属性显示视图,例如 item.image、item.title、item.descriptionText 等。