我第一次尝试使用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>


我已经在项目的设置页面中添加了核心数据。现在,当我使用github页面示例中提供的代码时:

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


我收到上面的错误。我忘记了什么吗?我一直在搜索一段时间,但无法弄清楚。

我正在使用Xcode 5.0.2和iOS 7。

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

最佳答案

从文档:

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

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

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


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

关于ios - ObjectiveRecord nil模型错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20154418/

10-13 03:00