在使用 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'
我选项 + 单击此 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
请!,我快疯了!
谢谢你!