我用xcode 3.2.5開始一個新的coredata項目後出現了一些問題...我之前的項目與核心數據(在以前的xcode)工作正常,所以我不知道什麼是區別??coredata問題nsurl可能不會響應stringByAppendingPathComponent
所以我得到的,當我建立和去調用核心數據視圖的誤差>
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
奇怪的是,在我的* AppDelegate.m,在(編輯感謝羅格,但仍不工作!)
- (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包括在本(@ 「路徑=%@」,[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)lastObject]);
這使我在控制檯:
path= /Users/mkss9/Library/Application Support/iPhone Simulator/4.2/Applications/2F364C20-2B87-4ABB-AA3E-FB6F7C15096F/Documents
請!即時得到瘋了!
謝謝!
我明白了,但爲什麼這個確切的代碼在我以前的項目中工作?即使是蘋果的coredatabooks例子也使用這個> NSString * storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@「CoreDataBooks.sqlite」]; 那會是什麼呢?謝謝! – MaKo 2011-02-11 02:18:14