ios – 重命名coredata .xcdatamodeld文件和迁移

前端之家收集整理的这篇文章主要介绍了ios – 重命名coredata .xcdatamodeld文件和迁移前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们已将两个分离的应用程序合并到同一工作空间中的2个目标.两者都有他们的核心数据模型(app1.xcdatamodeld和app2.xcdatamodeld).

现在两者都在同一个工作空间,所以不需要2个模型,因为它们是99%相似的.所以我想将.xcdatamodeld包的名称更改为allApps.xcdatamodeld.我可以重命名它,但是在这样做时,我没有找到关于迁移行为的任何参考.

这是错误

2015-07-28 09:04:06.079 AppName[51306:1423128] CoreData: error:
-addPersistentStoreWithType:sqlite configuration:(null) URL:file:///Users/shani/Library/Developer/CoreSimulator/Devices/EA75A69F-B108-4036-AB3D-B923F83D16DE/data/Containers/Data/Application/B1CB3AF3-DEF4-40DF-9A61-721063ECBB1D/Documents/AppName.sqlite
options:{
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
    NSsqlitePragmasOption =     {
        "journal_mode" = WAL;
    }; } ... returned error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error
134130.)" UserInfo=0x7fc39c194360 {URL=file:///Users/shani/Library/Developer/CoreSimulator/Devices/EA75A69F-B108-4036-AB3D-B923F83D16DE/data/Containers/Data/Application/B1CB3AF3-DEF4-40DF-9A61-721063ECBB1D/Documents/AppName.sqlite,Metadata={
    NSPersistenceFrameworkVersion = 519;
    NSStoreModelVersionHashes =     {
        Attempt = <b4d1e878 69a97917 e751a67c 89e1887a ae4df1dc f380e4ee c9585f60 f39ff51e>;
        BookmarkFlashcard = <33112f7c 2fa20bec eb2e019c b5d619b4 92be2547 a65fabee 1ac86ab7 92dd77bb>;
        BookmarkQuestion = <38634b49 71f0d43c 6f9fbba9 bc2f1b81 675c9b3c f2da017e fc8de9d8 4e18a4a0>;
        Category = <b0e4d91b 0c0ebc71 ed0f403c 9a0eec20 fc1686aa 0169bc60 4bcc7e57 165bce15>;
    };
    NSStoreModelVersionHashesVersion = 3;
    NSStoreModelVersionIdentifiers =     (
        ""
    );
    NSStoreType = sqlite;
    NSStoreUUID = "F1B37CD0-8B89-4893-A262-1013C3544026";
    "_NSAutoVacuumLevel" = 2; },reason=Can't find model for source store} with userInfo dictionary {
    URL = "file:///Users/shani/Library/Developer/CoreSimulator/Devices/EA75A69F-B108-4036-AB3D-B923F83D16DE/data/Containers/Data/Application/B1CB3AF3-DEF4-40DF-9A61-721063ECBB1D/Documents/AppName.sqlite";
    Metadata =     {
        NSPersistenceFrameworkVersion = 519;
        NSStoreModelVersionHashes =         {
            Attempt = <b4d1e878 69a97917 e751a67c 89e1887a ae4df1dc f380e4ee c9585f60 f39ff51e>;
            BookmarkFlashcard = <33112f7c 2fa20bec eb2e019c b5d619b4 92be2547 a65fabee 1ac86ab7 92dd77bb>;
            BookmarkQuestion = <38634b49 71f0d43c 6f9fbba9 bc2f1b81 675c9b3c f2da017e fc8de9d8 4e18a4a0>;
            Category = <b0e4d91b 0c0ebc71 ed0f403c 9a0eec20 fc1686aa 0169bc60 4bcc7e57 165bce15>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
            ""
        );
        NSStoreType = sqlite;
        NSStoreUUID = "F1B37CD0-8B89-4893-A262-1013C3544026";
        "_NSAutoVacuumLevel" = 2;
    };
    reason = "Can't find model for source store"; } 2015-07-28 09:04:06.089 AppName[51306:1423128] CoreData: annotation:
NSPersistentStoreCoordinator's current model hashes are {
    Attempt = <b4d1e878 69a97917 e751a67c 89e1887a ae4df1dc f380e4ee c9585f60 f39ff51e>;
    BookmarkFlashcard = <33112f7c 2fa20bec eb2e019c b5d619b4 92be2547 a65fabee 1ac86ab7 92dd77bb>;
    BookmarkQuestion = <38634b49 71f0d43c 6f9fbba9 bc2f1b81 675c9b3c f2da017e fc8de9d8 4e18a4a0>;
    Category = <b0e4d91b 0c0ebc71 ed0f403c 9a0eec20 fc1686aa 0169bc60 4bcc7e57 165bce15>; }

有没有办法在已经在生产中的应用程序中将name1.xdatamodel重命名为name2.xdatamodel?

谢谢

解决方法

而不是重命名app1.xcdatamodeld或app2.xcdatamodeld,您应该创建一个新的(allApps.xcdatamodeld).这个新的一个模型可以只是一个你想要保留的模型的副本.

然后在两个目标的每个目标中添加一个.xcmappingmodel文件并将其链接到allApps.xcdatamodeld并执行任何所需的翻译.

coreData的工作方式,您将需要保留原始的app1和app2 xcdatamodeld文件,以确保您永远不会破坏您的最旧应用程序仍然在其设备上运行的用户.

文件>新>文件>核心数据>映射模型
选择源模型,然后单击下一步.

选择目标数据模型,然后单击下一步.

在你的另一个目标app2再次这样做,你应该可以.

猜你在找的iOS相关文章