【问题标题】:Core Data crash my appCore Data 使我的应用程序崩溃
【发布时间】:2012-07-16 21:15:45
【问题描述】:

我使用核心数据构建了我的应用程序。它适用于具有两个属性的实体。 当我想添加具有单个属性的新实体时,我的应用程序在启动时崩溃。

2012-07-16 23:11:13.579 myApp[6773:fb03] Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x6bb36e0 {metadata=<CFBasicHash 0x6bbae90 [0x1748b48]>{type = immutable dict, count = 7,
entries =>
    2 : <CFString 0x6bbab30 [0x1748b48]>{contents = "NSStoreModelVersionIdentifiers"} = <CFArray 0x6bbaf20 [0x1748b48]>{type = immutable, count = 1, values = (
    0 : <CFString 0x1743cd8 [0x1748b48]>{contents = ""}
)}
    4 : <CFString 0x6bbab60 [0x1748b48]>{contents = "NSPersistenceFrameworkVersion"} = <CFNumber 0x6bbaa30 [0x1748b48]>{value = +386, type = kCFNumberSInt64Type}
    6 : <CFString 0x6bbaec0 [0x1748b48]>{contents = "NSStoreModelVersionHashes"} = <CFBasicHash 0x6bbafb0 [0x1748b48]>{type = immutable dict, count = 1,
entries =>
    2 : <CFString 0x6bbaf40 [0x1748b48]>{contents = "AllFamille"} = <CFData 0x6bbaf60 [0x1748b48]>{length = 32, capacity = 32, bytes = 0x5a5b78eb9edf4005bbe8a8d5e85fd102 ... 208bdf48b8b44695}
}

    7 : <CFString 0x1101ad8 [0x1748b48]>{contents = "NSStoreUUID"} = <CFString 0x6bbad30 [0x1748b48]>{contents = "45640157-116E-4616-93C5-2DA6027F4E9C"}
    8 : <CFString 0x1101978 [0x1748b48]>{contents = "NSStoreType"} = <CFString 0x1101988 [0x1748b48]>{contents = "SQLite"}
    9 : <CFString 0x6bba9e0 [0x1748b48]>{contents = "_NSAutoVacuumLevel"} = <CFString 0x6bbb000 [0x1748b48]>{contents = "2"}
    10 : <CFString 0x6bbaef0 [0x1748b48]>{contents = "NSStoreModelVersionHashesVersion"} = <CFNumber 0x6d84b60 [0x1748b48]>{value = +3, type = kCFNumberSInt32Type}
}
, reason=The model used to open the store is incompatible with the one used to create the store}, {
    metadata =     {
        NSPersistenceFrameworkVersion = 386;
        NSStoreModelVersionHashes =         {
            AllFamille = <5a5b78eb 9edf4005 bbe8a8d5 e85fd102 3c6d4040 f1b7fc6c 208bdf48 b8b44695>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
            ""
        );
        NSStoreType = SQLite;
        NSStoreUUID = "45640157-116E-4616-93C5-2DA6027F4E9C";
        "_NSAutoVacuumLevel" = 2;
    };
    reason = "The model used to open the store is incompatible with the one used to create the store";
}

【问题讨论】:

  • 每次对模型进行任何更改时,请确保从模拟器中删除应用程序..

标签: iphone xcode ios5 core-data


【解决方案1】:

这可能是因为您添加了该属性。因此,您的新数据库与旧数据库不一致。尝试删除模拟器文件夹下的数据库,然后重新运行。

【讨论】:

    【解决方案2】:

    出现此问题是因为用于保存数据库的托管对象模型不同,因为您添加了新实体,因此修改后的托管对象模型无法用于加载使用前一个模型保存的数据。

    如果您正在使用数据库的第一个版本,您可以从模拟器/设备中删除应用程序。但是,如果您要更改已发布的应用程序,这可能会成为一个大问题,因为您不能要求用户在安装新版本之前卸载您的应用程序。

    在这种情况下,您应该创建一个新版本的托管对象模型,然后配置 Core Data 以在您的数据库上执行从以前的模型版本到最新版本的轻量级迁移。

    请关注the steps detailed in the documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      • 1970-01-01
      • 2012-05-02
      相关资源
      最近更新 更多