问题描述
我们有2个独立的应用程序,已将它们合并到同一工作区中的2个目标。两者都有其核心数据模型( app1.xcdatamodeld
和 app2.xcdatamodeld
)。
We had a 2 separated apps that we have merged to 2 targets in the same workspace. Both had their core data model (app1.xcdatamodeld
and app2.xcdatamodeld
).
现在两者都在同一个工作空间中,因为99%相似,所以不需要两个模型。因此,我想将 .xcdatamodeld
包的名称更改为 allApps.xcdatamodeld
。我能够重命名它,但是这样做时我找不到任何有关迁移行为的参考。
Now that both are in the same workspace there is no need for 2 models as they are 99% similar. So I want to change the name of the .xcdatamodeld
package to allApps.xcdatamodeld
. I was able to rename it but I do not find any reference about the behaviour of migration when doing so.
这是错误-
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生产?
Is there a way to rename name1.xdatamodel to name2.xdatamodel in an app that is already in production ?
谢谢
推荐答案
而不是重命名app1.xcdatamodeld或app2.xcdatamodeld,则应创建一个新的(allApps.xcdatamodeld)。这个新的模型可以只是您想要保留的任何模型的副本。
Rather than renaming the app1.xcdatamodeld or the app2.xcdatamodeld you should create a new one (allApps.xcdatamodeld). This new one model can be just a copy of whichever model you want to keep.
然后在两个目标中的每个目标中添加一个.xcmappingmodel文件并将其链接到allApps .xcdatamodeld并执行所需的翻译。
Then in each of the two targets add an .xcmappingmodel file and link it to the allApps.xcdatamodeld and perform any translations needed.
coreData的工作方式,您需要保留原始的app1和app2 xcdatamodeld文件,以确保您永远不会破坏用户
The way coreData works, you'll want to keep the original app1 and app2 xcdatamodeld files around to ensure that you never break a user who happens to have your very oldest app still running on their device.
文件>新建>文件>核心数据>映射模型。
选择源模型,然后单击下一步。
File > New > File > Core Data > Mapping Model.Choose the source model and click Next.
选择目标数据模型,然后单击下一步。
Choose the Target data model and click Next.
在您的app2的其他目标中再次执行此操作,您应该可以。
Do this again in your other target for app2 and you should be OK.
这篇关于重命名coredata .xcdatamodeld文件并迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!