【发布时间】:2012-02-23 23:31:34
【问题描述】:
我正在使用位于 http://nachbaur.com/blog/smarter-core-data 的 Core Data Singleton。
我的 AP.xcdatamodeld 文件包含一个名为 Customers 和 Appointments 的实体。
我遇到的问题是这部分代码。
NSString * const kDataManagerBundleName = @"AP";
NSString * const kDataManagerModelName = @"AP";
NSString * const kDataManagerSQLiteName = @"AP.sqlite";
- (NSManagedObjectModel*)objectModel {
if (_objectModel)
return _objectModel;
NSBundle *bundle = [NSBundle mainBundle];
if (kDataManagerBundleName) {
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:kDataManagerBundleName ofType:@"bundle"];
bundle = [NSBundle bundleWithPath:bundlePath];
}
NSString *modelPath = [bundle pathForResource:kDataManagerModelName ofType:@"momd"];
NSLog(@"Path: %@",modelPath);
_objectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]];
return _objectModel;
}
问题是 modelPath 为空。
我进入我的模拟器并右键单击 .app 并浏览它的内容并看到一个名为 AP.momd 和 Appointments.momd 的文件夹。所以我不知道为什么它会返回 null,因为文件存在。
是我的文件名错误还是路径错误?为什么modelPath为空?
【问题讨论】:
标签: objective-c core-data ios5