我正在使用以下核心数据保存代码,但它没有保存。 managedObjectContext由提供新上下文的工厂类传递。
- (void)save{
NSError *error = nil;
// save the data in context
if ([managedObjectContext hasChanges]) {
if ([managedObjectContext save:&error]) {
if (error) {
DEBUGLOG(@"%@ saving faild with error code: %ld and message: %@", NSStringFromClass([self class]), (long)error.code, error.localizedDescription);
}
else{
DEBUGLOG(@"%@ managedObjectContext save success!!!!!!!!", NSStringFromClass([self class]));
// succesufuly saved data
[self updateLastSuccessSyncGet];
}
}
else{
DEBUGLOG(@"%@ managedObjectContext save failed!!!!!!!!", NSStringFromClass([self class]));
DEBUGLOG(@"%@ saving failed with error code: %ld and message: %@", NSStringFromClass([self class]), (long)error.code, error.localizedDescription);
}
}
}
答案 0 :(得分:0)
您使用哪种队列并发类型?通常它会发生,因为您在一个线程中运行。在这种情况下,您应该使用私有并发类型,如:
NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];