1

我完全糊涂了。这段代码:

 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:]: object cannot be nil”

(我将 alloc 和 init 分成两行,这样我就可以看到它在哪里吹。它是 initWithFileURL 爆炸,只要我点击“step into”。)

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

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

这完全符合预期。所以,正如我所说,我很困惑。我错过了一些明显的东西吗?

4

1 回答 1

0

As the error you are getting relates to passing a nil pointer to a NSMutableArray method and you aren't working with arrays here, I would say the issue is most likely not with your code. I also read through it and couldn't find a problem. The issue is most likely with your simulator, which can have problems from time to time. It is a good idea to reset the settings and create a new build. The issue is handled well here, and directly relates to this same issue when working with Core Data.

于 2013-08-09T04:31:36.833 回答