Xcode核心数据错误

时间:2014-05-16 21:58:47

标签: xcode core-data

我刚刚关注了CoreData的教程,但遇到了一个问题。 首先myApp崩溃了,因为我没有正确命名数据库(如教程中所示),通过调试器找到了。 但是现在我的程序执行得很好,但是引发了以下错误:

Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed

这是以下方法:

    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
    /*
     Replace this implementation with code to handle the error appropriately.

     abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 

     Typical reasons for an error here include:
     * The persistent store is not accessible;
     * The schema for the persistent store is incompatible with current managed object model.
     Check the error message to determine what the actual problem was.


     If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.

     If you encounter schema incompatibility errors during development, you can reduce their frequency by:
     * Simply deleting the existing store:
     [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

     * Performing automatic lightweight migration by passing the following dictionary as the options parameter:
     @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}

     Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.

     */
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

但我无法弄清楚出了什么问题。据我所知,错误是,我用来创建条目的函数与检索它们的函数不同,这是正确的吗? 如果是这样,我该如何解决?还有什么其他信息需要你帮助我解决这个问题?

我现在已经打了几个小时关于这个问题: - /

哦BTW这里是控制台(或调试窗口)输出:

2014-05-16 16:47:57.380 TimeStamp[884:60b] User clicked Save
2014-05-16 16:47:57.399 TimeStamp[884:60b] Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0xd166b20 {metadata={
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes =     {
    Entity = <a8bc66e2 f3ce9700 9c39bc5d 3ea64ca6 69e06023 3cc0f8e1 2768a9d5 5a520a0d>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers =     (
    ""
);
NSStoreType = SQLite;
NSStoreUUID = "588B9127-5774-45B3-8BF0-2C5CD0F07321";
"_NSAutoVacuumLevel" = 2;}, reason=The model used to open the store is incompatible with the one used to create the store}, {
metadata =     {
    NSPersistenceFrameworkVersion = 479;
    NSStoreModelVersionHashes =         {
        Entity = <a8bc66e2 f3ce9700 9c39bc5d 3ea64ca6 69e06023 3cc0f8e1 2768a9d5 5a520a0d>;
    };
    NSStoreModelVersionHashesVersion = 3;
    NSStoreModelVersionIdentifiers =         (
        ""
    );
    NSStoreType = SQLite;
    NSStoreUUID = "588B9127-5774-45B3-8BF0-2C5CD0F07321";
    "_NSAutoVacuumLevel" = 2;
};
reason = "The model used to open the store is incompatible with the one used to create the store";}
(lldb)

谢谢你们!

1 个答案:

答案 0 :(得分:5)

您需要从模拟器或设备中删除该应用程序,然后重新安装(只需编译)它 原因是您更改了底层数据库结构。所以现在你必须删除旧的数据库。这将导致根据您的新规范再次创建数据库。请注意,每次更改数据库时都需要删除并重新安装应用程序。