ObjectiveRecord nil模型错误

时间:2013-11-22 21:01:50

标签: ios xcode core-data cocoapods

我第一次尝试使用CocoaPods和ObjectiveRecord。 ObjectiveRecord's github page

当我尝试保存对象时,出现以下错误:

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'
*** First throw call stack:
(
    0   CoreFoundation                      0x01aae5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x018318b6 objc_exception_throw + 44
    2   CoreData                            0x00023b0e -[NSPersistentStoreCoordinator initWithManagedObjectModel:] + 398
    3   ObjectiveRecordTest                 0x00003691 -[CoreDataManager persistentStoreCoordinatorWithStoreType:storeURL:] + 193
    4   ObjectiveRecordTest                 0x000030f9 -[CoreDataManager persistentStoreCoordinator] + 169
    5   ObjectiveRecordTest                 0x00002dba -[CoreDataManager managedObjectContext] + 106
    6   ObjectiveRecordTest                 0x00003f26 +[NSManagedObjectContext(ActiveRecord) defaultContext] + 86
    7   ObjectiveRecordTest                 0x0000477a +[NSManagedObject(ActiveRecord) create] + 58
    8   ObjectiveRecordTest                 0x00002112 -[ViewController savePressed:] + 82
    9   libobjc.A.dylib                     0x01843874 -[NSObject performSelector:withObject:withObject:] + 77
    10  UIKit                               0x005a10c2 -[UIApplication sendAction:to:from:forEvent:] + 108
    11  UIKit                               0x005a104e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    12  UIKit                               0x006990c1 -[UIControl sendAction:to:forEvent:] + 66
    13  UIKit                               0x00699484 -[UIControl _sendActionsForEvents:withEvent:] + 577
    14  UIKit                               0x00698733 -[UIControl touchesEnded:withEvent:] + 641
    15  UIKit                               0x005de51d -[UIWindow _sendTouchesForEvent:] + 852
    16  UIKit                               0x005df184 -[UIWindow sendEvent:] + 1232
    17  UIKit                               0x005b2e86 -[UIApplication sendEvent:] + 242
    18  UIKit                               0x0059d18f _UIApplicationHandleEventQueue + 11421
    19  CoreFoundation                      0x01a3783f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    20  CoreFoundation                      0x01a371cb __CFRunLoopDoSources0 + 235
    21  CoreFoundation                      0x01a5429e __CFRunLoopRun + 910
    22  CoreFoundation                      0x01a53ac3 CFRunLoopRunSpecific + 467
    23  CoreFoundation                      0x01a538db CFRunLoopRunInMode + 123
    24  GraphicsServices                    0x02e9e9e2 GSEventRunModal + 192
    25  GraphicsServices                    0x02e9e809 GSEventRun + 104
    26  UIKit                               0x0059fd3b UIApplicationMain + 1225
    27  ObjectiveRecordTest                 0x000028ad main + 141
    28  libdyld.dylib                       0x02b4070d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

这就是我的Podfile的样子:

platform :ios
pod 'ObjectiveRecord'

我正在使用新的xcworkspace文件而不是旧的xcode项目文件,我在.pch文件中导入了以下两个:

#import "ObjectiveRecord.h"
#import <CoreData/CoreData.h>

我在项目的设置页面中添加了Core Data。现在,当我使用github页面示例中提供的代码时:

Person *john = [Person create];
john.name = @"John";
[john save];

我收到上面的错误。我忘记了什么吗?我一直在寻找一段时间,但我无法理解。

我正在使用Xcode 5.0.2和iOS 7。

更新 事实证明,在一般项目设置中,在框架和库部分中,有一个红色的“libPods.a”条目。这意味着它不见了,对吧?这可能是问题吗?

2 个答案:

答案 0 :(得分:5)

来自doc:

自定义CoreData模型或.sqlite数据库

如果您手动添加了核心数据,则可以在CoreDataManager上更改自定义模型和数据库名称

[CoreDataManager sharedManager].modelName = @"MyModelName";
[CoreDataManager sharedManager].databaseName = @"custom_database_name";

https://github.com/mneorr/ObjectiveRecord/blob/master/README.md 阅读文档总是有帮助的。

答案 1 :(得分:0)

好的,我通过将Model.xcdatamodeld重命名为appname.xcdatamodeld来修复错误。我不确定为什么要修复它但是,我总是将我的模型命名为#34; Model&#34;以前,没有任何问题,但现在它的工作原理。我希望这可以帮助其他人解决这个问题。我也发现红色的&#34; libPods.a&#34;进入并不意味着它缺失。所以,即使它是红色的,一切都很好。