如何使用Core Data在Cocoa中上传和存储文件? [英] How to upload and store files in Cocoa with Core Data?

查看:209
本文介绍了如何使用Core Data在Cocoa中上传和存储文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程式,我想要能够上传档案。我可以想象序列化数据,把它放入一个数组,然后序列化数组,并把它放入Core Data,但这似乎不对。我也可以想象将文件复制到应用程序的支持文件,获得NSURL的那些和存储数组或NSURLs。

I have an app which I would like to be able to upload files to. I could imagine serializing the data, putting that into an array, then serializing the array and putting that into Core Data but that doesn't quite seem right. I could also imagine copying the files into the application's supporting files, getting the NSURL for those and storing the array or NSURLs.

在任何情况下,NSURL不是Core Data中的属性选项,也不是NSArray。

In any case, NSURL is not an attribute option, nor is NSArray, in Core Data.

另一个潜在问题 - 我的目标是让iPhone应用程式和桌面应用程式同步处理。所以我想从我的iPhone上传图片或从我的桌面上传文件,并使一切工作正常。我不知道复制文件将与iPhone兼容。

Another potential issue - my goal is to make an iPhone App and Desktop App that sync together. So I want to upload images from my iPhone or upload files from my desktop and have everything work fine together. I'm not sure copying the files over would be compatible with iPhone. I want to be able to upload any type of file as well.

问题:

如何在iOS上储存图片?

如何在Mac OS X上存储文件?

我将二进制数据存储在核心数据中?我是否将文件复制到目录并存储NSURL?

THE QUESTION:
How do I store images on iOS?
How do I store files on Mac OS X?
Do I store binary data in core data? Do I copy files into a directory and store an NSURL?

奖金问题:

如何在iOD和Mac OS X应用程序之间同步?

BONUS QUESTION:
How do I sync between iOD and Mac OS X applications?

澄清:

抱歉对此问题的任何混淆。这里有一个更干净的版本:

CLARIFICATION:
Sorry about any confusion from this question. Here's a cleaner version:

我的核心数据模型由一个Entry实体组成,它有一个名称NSString属性和一个一对多的关系,实体。此文件实体具有名称NSString属性和尚未确定的第二属性。这第二个属性可能是(从我可以想出)一个可变形的NSData表示的一些文件,NSURL的可变形表示指向一些文件(我仍然不可能与可变形的工作,所以我可能错了所有这一切...)或文件数据的二进制blob。可能有其他选择,但重点是能够从OS X或iOS保存或上传文件到此程序,并将数据库同步到一起。

My Core Data Model consists of an "Entry" entity that has a name NSString attribute and a one-to-many relationship with a "File" entity. This file entity has a name NSString attribute and a second attribute that has yet to be determined. This second attribute is maybe (from what I can come up with) a transformable NSData representation of some file, a transformable representation of NSURL that points to some file (I am still uncomforable with how transformable works, so I could be wrong about all this...), or a binary blob of the file data. There may be other choices, but the point is is to be able to save or "upload" files to this program from either OS X or iOS and sync the databases together.

我有一个表视图的OS X应用程序,显示所有条目的名称。选择条目的名称,您将有一个其指向的文件列表。双击文件,它应该打开与默认应用程序,就像它将与Finder。您还应该能够从Core Data中导出文件,并将它们保存到应用程序之外的目录中。

I have an OS X Application with a table view that displays a names of all the Entry's. Select the name of an Entry and you will have a list of Files that it points to. Double click the file and it should open with the default application just as it would with Finder. You should also be able to export the files out of Core Data and save them back to a directory outside of the app.

我还有一个iOS应用程序,拍摄照片或多张照片,将其保存到文件实体,从条目实体(使用与OS X应用程序相同的Core Data模型)指向这些文件,并与我的OS X应用程序离线同步,都有相同的数据。

I also have an iOS Application that allows me to take a picture or multiple pictures, save them to "File" entities, point to those files from an "Entry" entity (using the same Core Data model as the OS X Application), and offine sync with my OS X Application so both applications have all the same data.

我希望清除一切。

感谢您的帮助,

Chet

推荐答案

要在设备之间同步核心数据,我建议你看看这个网站,我已经发布的Core Data和iCloud集成的iOS和OS X应用程序的详细信息。

To sync core data between devices I would suggest you take a look at this site where I have posted details on Core Data and iCloud integration for both iOS and OS X apps. It is beyond the scope of an answer on this site.

http://ossh.com.au/design-and-technology/software-development/

这篇关于如何使用Core Data在Cocoa中上传和存储文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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