1
如果我在主線程創建的NSFetchRequest
像這樣:NSFetchRequest是否包含NSManagedObjectID安全地跨越線程邊界的NSPredicate?
NSManagedObject *bar = ...;
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Foo"];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"SELF.bar == %@",
[bar objectID]]];
它是安全的通過這個NSFetchRequest
與包含NSManagedObjectID
到後臺線程像這樣的NSPredicate
?
NSManagedObject *bar = nil;
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Foo"];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"SELF.bar == %@",
[bar objectID]]];
NSPersistentStoreCoordinator *persistentStoreCoordinator = ...;
[[NSBlockOperation blockOperationWithBlock:^{
NSManagedObjectContext *managedObjectContext = [NSManagedObjectContext new];
[managedObjectContext setPersistentStoreCoordinator:persistentStoreCoordinator];
NSArray *foos = [managedObjectContext executeFetchRequest:fetchRequest
error:NULL];
}] start];