使用iCloud设计的核心数据 [英] Core Data with iCloud design

查看:180
本文介绍了使用iCloud设计的核心数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在iOS 7上的一些我想要使用核心数据与iCloud,这是工作很好,我想要一些输入的问题是以下。核心数据对象具有相关的图像/大文本文件,我正在文件系统上存储为文件,只是将这些项目的URL设置为字符串属性。现在显然这不会只是与iCloud Core Data同步,因为iCloud没有这些文件的概念。我想知道你是否有任何建议如何处理这个?



1)我可以直接存储图像数据和大文本文件作为核心数据属性,但似乎不是最好的方法



2)我可以使用iCloud来存储文档,然后以某种方式尝试保持不同iOS设备中的文件之间的同步,但这可能会变得麻烦。



3)其他解决方案。



有任何建议吗?



丹尼尔

解决方案

如果您以编程方式设置模型,请添加消息到 setAllowsExternalBinaryDataStorage:以允许Core Data决定何时将其作为记录或单独文件自动保存。 Core Data在决定使用外部文件时为其管理外部文件,因此它也应该在iCloud中正常工作。

  NSAttributeDescription * imageAttribute; 
//初始化,设置,添加到模型等
[imageAttribute setAttributeType:NSBinaryDataAttributeType];
[imageAttribute setAllowsExternalBinaryDataStorage:YES];

在模型编辑器UI中也有相应的属性复选框。



https://developer.apple.com/library/ios/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSAttributeDescription_Class/reference.html#// apple_ref / doc / uid / TP30001175-SW26


Im on iOS 7 and want to use core data with iCloud, this is working well, the issue I wanted some input on is the following.

Some of my Core Data objects have related images/large text files which I was storing as files on the file system and just setting the url of these items as string properties. Now obviously this wont just work with iCloud Core Data sync because iCloud has no notion of these files. I was wondering if you had any suggestions on how to handle this?

1) I could store the image data and large text files as core data properties directly but it does not seem to be the best way to go

2) I could use iCloud to also store the documents and then somehow try to keep sync between the files in different iOS devices, but this could potentially get messy.

3) Some other solution.

Any Suggestions?

Regards

Daniel

解决方案

If you are setting up the model programmatically, add a message to setAllowsExternalBinaryDataStorage: to allow Core Data to decide when to save it as a record or separate file automatically. Core Data manages the external files for you when it decides to use them, so it should "just work" in iCloud as well.

NSAttributeDescription * imageAttribute;
//Initialise, setup, add to model, etc
[imageAttribute setAttributeType: NSBinaryDataAttributeType];
[imageAttribute setAllowsExternalBinaryDataStorage:YES];

There is a corresponding checkbox for the attribute in the model editor UI as well.

https://developer.apple.com/library/ios/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSAttributeDescription_Class/reference.html#//apple_ref/doc/uid/TP30001175-SW26

这篇关于使用iCloud设计的核心数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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