每次,当我保存我NSManagedObjectContext
的,它需要10 秒或更多。
这是我的代码:
dispatch_queue_t requestQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
dispatch_async(requestQueue, ^{
NSManagedObjectContext *manageContext = [[NSManagedObjectContext alloc]init];
[manageContext setPersistentStoreCoordinator:[[OKCoreManager sharedManager] persistentStoreCoordinator]];
Card *cardObject = (Card *)[NSEntityDescription insertNewObjectForEntityForName:@"Card" inManagedObjectContext:manageContext];
cardObject.name = self.name;
cardObject.title = self.title;
cardObject.email = self.email;
cardObject.address = self.address;
cardObject.stacks = self.stackObject;
cardObject.contact =self.contact;
NSError *error;
if (![[OKCoreManager sharedManager]saveManagedObjectContext:manageContext])
{
NSLog(@"Problem saving: %@", [error localizedDescription]);
dispatch_sync(requestQueue, ^{
iCallBack(FALSE,selfObject);
});
}
else
{
dispatch_sync(requestQueue, ^{
iCallBack(TRUE,selfObject);
});
}
manageContext = nil;
});