我需要獲取所有對象的主鍵,怎麼實現?
推薦的代碼:
[NSManagedObject objectID].
訪問和獲取對象的最佳途徑:
NSFetchRequest* request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setResultType:NSManagedObjectIDResultType];
[request setFetchBatchSize:20];
NSError* error = nil;
NSArray* items = [context executeFetchRequest:request error:&error];
for (NSManagedObjectID* objectID in items) {
NSManagedObject* object = [context objectWithID:objectID];
...
}