简体   繁体   English

将iOS / Mac应用程序与dame数据模型同步?

[英]Sync iOS / Mac app with dame data model?

I crated an iOS app that uses core data, basically a todo list. 我创建了一个使用核心数据(基本上是待办事项列表)的iOS应用。

I want to create an OS X app that will also show the todo list and sync with the iOS device. 我想创建一个OS X应用程序,该应用程序还将显示待办事项列表并与iOS设备同步。 I'm not interested in iCloud atm (sync would use bluetooth/internal network) though it's good if it can be enabled later. 我对iCloud atm不感兴趣(同步将使用蓝牙/内部网络),但是如果以后可以启用它会很好。

I have currently little idea about OS X development but I found I can use a document based app and core data. 目前,我对OS X的开发几乎一无所知,但发现可以使用基于文档的应用程序和核心数据。 But I would have to replicate the xcdatamodel of the iOS app. 但是我必须复制iOS应用程序的xcdatamodel。 Is there a way I can share the data model? 有什么方法可以共享数据模型? Do I maybe have to use something different than core data? 是否可能需要使用与核心数据不同的内容? I don't want to have to maintain 2 exact copies... I also don't want to use 3d party libraries (though advices are welcome as a comment). 我不想保留2个确切的副本...我也不想使用3d派对库(尽管欢迎提出建议作为评论)。 Probably this can be solved using scripting but I wonder if there's a better way. 可能可以使用脚本解决此问题,但我想知道是否有更好的方法。

So the question was how to avoid replicating your xcdatamodel and have only one versioned xcdatamodel in your iOS or in your OS X XCode project/workspace and share it with the other one?!? 因此,问题是如何避免复制您的xcdatamodel,并且在您的iOS或OS X XCode项目/工作区中只有一个版本化的xcdatamodel并与另一个共享?

Whenever the model has changed you can use the momc tool and compile the "xcdatamodel" file to a "momd" file. 无论何时更改模型,都可以使用momc工具并将“ xcdatamodel”文件编译为“ momd”文件。 Only the "momd" file will be loaded at runtime by iOS/OS X App. iOS / OS X App将在运行时仅加载“ momd”文件。 The compile step looks like this: 编译步骤如下所示:

/Applications/Xcode.app/Contents/Developer/usr/bin/momc <your project folder>/MyApplication/MyApplication/MyApplication.xcdatamodeld/MyApplication.xcdatamodel <your destination folder>/my.momd

Now add "my.momd" as a new bundle resource in XCode project of the app with no model of its own. 现在,在应用程序的XCode项目中添加“ my.momd”作为新的捆绑包资源,而没有自己的模型。 Choose target settings go to "Build Phases" go to "Copy Bundle Resource" and add "my.momd". 选择目标设置,转到“构建阶段”,转到“复制捆绑资源”并添加“ my.momd”。

You need to change the code accordingly: 您需要相应地更改代码:

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"my" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

Of course ".xcdatamodeld" folder can be removed from the app project with no model of its own. 当然,“。xcdatamodeld”文件夹可以从应用程序项目中删除,而无需使用其自身的模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM