我完全糊涂了。这段代码:
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"
这完全符合预期。所以,正如我所说,我很困惑。我错过了一些明显的东西吗?