2011-02-08 110 views
0

我遇到了CoreData應用程序的問題......當您選擇使用核心數據存儲時,它在Apple提供的boiler plate代碼上崩潰。應用程序在CoreData PathForResource上崩潰

- (NSManagedObjectModel *)managedObjectModel { 

if (managedObjectModel_ != nil) { 
    return managedObjectModel_; 
} 
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"iLoveForLife" ofType:@"momd"]; 
NSURL *modelURL = [NSURL fileURLWithPath:modelPath]; 
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];  
return managedObjectModel_; 
} 

它說*終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因是: '* - [NSURL initFileURLWithPath:]:零字符串參數'

這裏的任何想法....

回答

0

不知何故,我失去了我的xcodedatamodeld文件。當我創建一個新的它叫做xcodedatamodel。

+0

我得到的是同樣的東西,但我的「媽媽」引用與我的xcdatamodel相同。這應該工作嗎? – quantumpotato 2011-04-25 17:49:10

+0

我所做的只是將文件從xcodedatamodel重命名爲xcodedatamodeld,並且工作正常。不知道爲什麼。 – logixologist 2011-05-27 06:46:47

-1

有同樣的問題。 我正在通過添加一個測試來查看modelURL是否爲零 - 它與所有數據模型現在在iOS5 SDK中「版本化」的事實有關。

我現在這樣做:

NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"iLoveForLife" 
                 ofType:@"momd"]; 
NSURL *modelURL = [NSURL fileURLWithPath:modelPath]; 
if (modelURL == nil) 
     NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"iLoveForLife" 
                   ofType:@"mom"]; 
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; 

注意 「ofType」 參數從momd變化的媽媽。我知道這並不理想,但它會讓你失去知覺。 只要我想通了,爲什麼發生這種情況,我會發布一些:-)

0

你應該使用下面的方法讓你的管理對象模型:

managedObjectModel_ = [NSManagedObjectModel mergedModelFromBundles:nil] 

它將爲所有搜索可用的主要應用程序包中的管理對象模型

相關問題