- [NSURL initFileURLWithPath:]:nil string parameter'on NSManagedObjectModel [英] -[NSURL initFileURLWithPath:]: nil string parameter' on NSManagedObjectModel

查看:257
本文介绍了 - [NSURL initFileURLWithPath:]:nil string parameter'on NSManagedObjectModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是试图进入核心数据的东西,并克服了蝙蝠。在我的AppDelegate我有以下代码:

Just trying to get into the Core Data stuff and getting crossed up right off the bat. In my AppDelegate I have the following code:

- (NSManagedObjectModel *)managedObjectModel {

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

其中@DataModel是我的.xcdatamodel文件的名称 - 正确?

Where @"DataModel" is the name of my .xcdatamodel file - is this correct?

推荐答案

通常更容易将其更改为

managedObjectModel_ = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];

然后如果是妈妈或妈妈,你还会得到这个模型。

Then if it is a mom or momd you will still get the model back.

这篇关于 - [NSURL initFileURLWithPath:]:nil string parameter'on NSManagedObjectModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆