仅将Core Data中的一个实体同步到iCloud [英] Syncing only one entity in Core Data to iCloud

查看:157
本文介绍了仅将Core Data中的一个实体同步到iCloud的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名iOS开发人员,正在尝试针对Feed阅读器应用程序使用iCloud和Core Data。我为两个实体设置了核心数据,一个实体为商品,另一个实体为渠道。 Channel实体包含的信息可用于将用户的订阅网站同步到其所有设备。在我自己的研究中,我只找到一种同步Core Data中两个实体的方法。我的问题是:是否可以仅将一个Core Data实体同步到iCloud?

I'm an iOS developer experimenting with iCloud and Core Data for a feed reader application. I have Core Data set up for two entities, one for an Item and another for a Channel. The Channel entity contains the information that I would use to have a user's subscribed websites synced to all their devices. In my own research, I have only found a way to sync both entities in Core Data. My question is: is it possible to sync only one Core Data entity to iCloud?

如果有帮助,我可以发布代码。

I can post my code if it would help.

推荐答案


是否可以仅将一个核心数据实体同步到iCloud?

Is it possible to sync only one Core Data entity to iCloud?

仅当它们存储在单独的持久性存储文件中

通过将选项传递给 addPersistentStoreWithType:configuration:URL:options:error:来配置iCloud。完成此操作后,永久性存储中的所有内容都将同步到iCloud。 iCloud没有针对每个实体的配置。

You configure iCloud by passing options to addPersistentStoreWithType:configuration:URL:options:error:. Once you do that, everything in the persistent store is synced to iCloud. There's no per-entity configuration for iCloud.

但是, NSPersistentStoreCoordiator 可以有多个持久性存储。您可以添加多个路径不同的路径,而不必对所有路径都使用相同的选项。您不能具有跨越持久性存储的关系,但是可以具有已获取的属性。那不是完全一样,但是在某些情况下,这是一个可行的替代方案。它们将为您提供一种单向的方式来查找一个或多个对象,并将它们作为属性值返回。文档中提到的用于获取属性的示例类似于iTunes播放列表,可能与您的情况类似。

However, NSPersistentStoreCoordiator can have multiple persistent stores. You add more than one, with different paths, and you don't have to use the same options on all of them. You can't have relationships that cross persistent stores, but you can have fetched properties. That's not quite the same, but in some cases it's a workable replacement. They'll give you a unidirectional way to look up one or more objects and return them as if they were a property value. The example mentioned in the docs for fetched properties is something like an iTunes playlist, which might be similar to your situation.

因此:是的,如果您愿意做一些额外的工作来实现它。

So: yes, sort of, if you're willing to do some extra work to make it happen.

这篇关于仅将Core Data中的一个实体同步到iCloud的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆