【发布时间】:2011-06-25 07:03:23
【问题描述】:
在使用 xcode 3.2.5 开始一个新的 coredata 项目后,我遇到了一些问题...我以前使用核心数据的项目(在以前的 xcode 中)运行良好,所以我不知道有什么区别??
所以我在构建并转到调用核心数据的视图时遇到的错误是>
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
奇怪的是,在我的 *AppDelegate.m 中(编辑感谢 Rog 但仍然无法正常工作!)
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator_ != nil) {
return persistentStoreCoordinator_;
}
NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"staff.sqlite"];
NSURL *storeUrl = [NSURL fileURLWithPath:storePath]; //new position for the storeUrl!
// Put down default db if it doesn't already exist
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:storePath]) {
NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"staff" ofType:@"sqlite"];
if (defaultStorePath) {
[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
}
}
在
NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"staff.sqlite"];
我收到警告
NSURL may not respond to '-stringByAppendingPathComponent'
I 选项 + 单击此 stringByAppendingPathComponent 并获取(未找到符号!!!!)
但在其他项目中,我会执行选项 + 单击相同的操作并获取定义!
- 那么这个警告与我的错误有关吗??
- 如何解决???
编辑, 将此包含在我的 viewDidLoad 中
NSLog(@"path= %@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]) ;
这给了我控制台:
path= /Users/mkss9/Library/Application Support/iPhone Simulator/4.2/Applications/2F364C20-2B87-4ABB-AA3E-FB6F7C15096F/Documents
拜托!我快疯了!!
谢谢!
【问题讨论】: