NSURagedObjectModel initWithContentsOfURL返回nil,尽管modelURL有效 [英] NSManagedObjectModel initWithContentsOfURL returns nil eventhough the modelURL is valid

查看:108
本文介绍了NSURagedObjectModel initWithContentsOfURL返回nil,尽管modelURL有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的NSManagedObjectModel返回nil event尽管路径正确。

my NSManagedObjectModel is returning nil eventhough the path is correct.

        NSString *modelKey = [NSString stringWithFormat:@"/%@/Model", name];
    NSString *modelPath = [((Configuration *)[Configuration shared]) stringEntry:modelKey];
    NSURL *modelURL = nil;
    if ( ! [modelPath contains:@"://"] ) {
        modelPath = PathForBundleResource( modelPath );
        modelURL = [NSURL fileURLWithPath:modelPath];
    }
    NSManagedObjectModel *m = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

NSString * PathForBundleResource(NSString * relativePath)

NSString *PathForBundleResource(NSString *relativePath)

    NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
return [resourcePath stringByAppendingPathComponent:relativePath];

我重置了模拟器,做了一个干净的构建,但没有任何帮助。

I've reset the simulator, did a clean build but nothing helped.

我是iPhone编程的新手(特别是核心数据)。

I'm new to iPhone programming (core data in particular).

非常感谢任何帮助。

编辑:我编辑了有关xcdatamodeld文件的原始帖子。它最初没有正确连接,但现在它仍然存在同样的问题。

I've edited the original post regarding the xcdatamodeld file. It wasn't linked up properly initially but now it is and still having the same problem.

编辑2:显然xcdatamodel的名称有一些变化名称链接后的xcdatamodel。它现在正在运作。感觉很蠢。不知道如何删除这个问题。

Edit 2: Apparently the name of the xcdatamodel had some variations to the name of the xcdatamodel after linkage. It's working now. Feeling so stupid. Don't know how to delete this question.

推荐答案

我在重命名.xcdatamodeld文件后遇到了同样的问题。关闭并重新打开Xcode客户端解决了这个问题。

I had the same problem after I renamed .xcdatamodeld file. The problem was solved by closing and reopening the Xcode client.

这篇关于NSURagedObjectModel initWithContentsOfURL返回nil,尽管modelURL有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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