Ios mergeChangesFromContextDidSaveNotification中的核心数据崩溃->;呼叫循环
我对CoreData有问题,我不知道更多。我将它与ICloud一起使用,并在两台iPhone上进行了测试 现在我一个接一个地在两部手机上启动我的应用程序。我在一部电话里加了一张唱片。只要两部手机都切换到“使用本地存储:0”,我就可以看到一部手机(接收更改通知的手机)上的内存 调用[self.howRUDocument.managedObjectContext合并更改fromContextDidSaveNotification:notification]时会发生这种情况;方法调试时,来自ContextDidSaveNotification的分步合并更改将永远不会到达下一行Ios mergeChangesFromContextDidSaveNotification中的核心数据崩溃->;呼叫循环,ios,core-data,Ios,Core Data,我对CoreData有问题,我不知道更多。我将它与ICloud一起使用,并在两台iPhone上进行了测试 现在我一个接一个地在两部手机上启动我的应用程序。我在一部电话里加了一张唱片。只要两部手机都切换到“使用本地存储:0”,我就可以看到一部手机(接收更改通知的手机)上的内存 调用[self.howRUDocument.managedObjectContext合并更改fromContextDidSaveNotification:notification]时会发生这种情况;方法调试时,来自Conte
- (id)initWithDocumentName:(NSString *)documentName {
self = [super init];
if (self) {
self.documentName = documentName;
iCloudCommunicator = [ICloudCommunicator sharedInstance];
[iCloudCommunicator registerForICloudAccountChange:self];
if ([iCloudCommunicator useICloud]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(documentChanged:)
name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
object:self.howRUDocument.managedObjectContext.persistentStoreCoordinator];
}
}
return self;
}
-(void) documentChanged:(NSNotification *)notification {
[self.howRUDocument.managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
}
这是我在探查器中看到的:
所以这是一个无限循环(这不是苹果的地址:-D)。有人知道为什么吗
另一件奇怪的事情是,这些方法位于类模型中。我有两个从这个类扩展而来的模型。一方面,合并工作正常,另一方面,我得到了上面的异常
非常感谢 我解决了这个问题。我把文件整理得一团糟。当创建并将其移动到云时,我移动了错误的文档URL。 还有一个竞争条件,所以文档在创建之前试图打开 我有这个代码,它工作得很好:
- (id)initWithDocumentName:(NSString *)documentName {
self = [super init];
if (self) {
_dataChangeListeners = [[NSMutableArray alloc] init];
self.documentName = documentName;
iCloudCommunicator = [ICloudCommunicator sharedInstance];
[iCloudCommunicator registerForICloudAccountChange:self];
if ([iCloudCommunicator useICloud]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(documentChanged:)
name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
object:self.howRUDocument.managedObjectContext.persistentStoreCoordinator];
}
}
return self;
}
-(void) documentChanged:(NSNotification *)notification {
[self.howRUDocument.managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
[self notifyDataChangeListeners];
}