【发布时间】:2010-02-18 15:02:44
【问题描述】:
今晚我花了几个小时试图创建一个设置,其中我有三个托管对象上下文 - 一个附加到我的应用程序的委托,一个在负责 UITableView 更新的 NSObject 子类中(通过 @987654323 @) 和 NSOperation 子类中的一个。
我可以通过观察NSManagedObjectContextDidSaveNotification 并在我的主线程上触发mergeChangesFromContextDidSaveNotification: 来使从NSOperation 子类到应用程序委托的更改顺利通过,但是当我尝试从我的UITableView 数据源,我得到以下异常:
2010-02-19 02:00:39.750 MyApp[44687:207] Serious application error. Exception was caught during Core Data change processing: *** -[NSCFArray initWithObjects:count:]: attempt to insert nil object at objects[0] with userInfo (null)
2010-02-19 02:00:39.750 MyApp[44687:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFArray initWithObjects:count:]: attempt to insert nil object at objects[0]'
如果有任何建议,我将不胜感激 - 我之前所有涉及 Core Data 托管对象上下文的设计都是非常简单的 1:1 同步场景。我的提议是否可行?
【问题讨论】:
-
你用过调试器吗?它告诉你关于你尝试将 nil 插入 NSArray 的什么?具体来说,中断 objc_exception_throw 并查明导致此问题的部分代码。
-
Joshua,它实际上来自: - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath * )newIndexPath { NSArray *paths = [NSArray arrayWithObject:newIndexPath];显然 NSArray 不能由 {0,0} 的 indexPath 初始化。仍在研究为什么会发生这种情况。
标签: cocoa cocoa-touch core-data