【问题标题】:Xcode core data errorXcode核心数据错误
【发布时间】:2014-07-05 11:47:36
【问题描述】:

我只是在学习有关 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();
}

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

我已经为这个问题烦恼了好几个小时了:-/

哦,顺便说一句,这里是控制台(或调试窗口)输出:

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)

谢谢大家!

【问题讨论】:

标签: xcode core-data


【解决方案1】:

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

【讨论】:

  • 您可以通过转到 iOS 模拟器并单击“重置内容和设置”并删除您的 ios 模拟器上所有已安装的应用程序来执行此操作!
  • @bucifer - 这是一种方法,但您也可以单击并按住您的应用程序,等待摆动,然后单击右上角的 x。就像您在真实设备上所做的那样。
猜你喜欢
  • 1970-01-01
  • 2015-10-28
  • 2012-01-20
  • 2011-10-30
  • 2012-03-28
  • 2012-02-16
  • 2010-12-19
  • 2011-01-02
相关资源
最近更新 更多