UIManagedDocument initWithURL因NSArray错误而崩溃



我完全弄糊涂了。此代码:

 NSFileManager *fileManager=[NSFileManager defaultManager];
    NSURL *documentURL=[fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
    documentURL = [documentURL URLByAppendingPathComponent:@"TrackerDB"];
    self.document = [UIManagedDocument alloc];
    self.document = [self.document initWithFileURL:documentURL];

会产生以下错误:*由于未捕获的异常"NSInvalidArgumentException"而终止应用程序,原因:"*-[__NSArrayM insertObject:atIndex:]:对象不能为nil"

(我把alloc和init分成两行,这样我就可以看到它在哪里爆炸。我一点击"step into",initWithFileURL就会爆炸。)

顺便说一下,self.document是一个@property (strong,nonatomic) UIManagedDocument *,URL是:

@"file://localhost/Users/rick/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/3FEA801E-9279-45A7-9606-853124A111C4/Documents/TrackerDB"

这完全符合预期。所以,正如我所说,我感到困惑。我是不是错过了一些显而易见的东西?

由于您收到的错误与将nil指针传递给NSMutableArray方法有关,并且您在这里不使用数组,因此我认为问题很可能与您的代码无关。我也通读了一遍,没有发现任何问题。这个问题很可能与您的模拟器有关,它可能会不时出现问题。重置设置并创建新版本是个好主意。这个问题在这里处理得很好,并且在使用Core Data时与这个问题直接相关。

最新更新