如何存储许多图像和.mp3文件的核心数据为iphone? [英] How to store many images and .mp3 files in core data for iphone?

查看:95
本文介绍了如何存储许多图像和.mp3文件的核心数据为iphone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对核心数据非常新,我试图学习如何存储大型文件,如图像和短的.mp3s。我的应用程序有大约300个不同的图像和短的.mp3s触发显示/播放通过用户交互,据我可以告诉,我应该使用核心数据来存储这些文件。

I am very new to core data and am trying to learn how to store large files, like images and short .mp3s. My app has about 300 different images and short .mp3s that are triggered to be displayed/played by user interaction, and as far as I can tell, I should use core data for storing these files.

我向我的xcode项目添加了一个核心数据.xc文件,并创建了一个带有属性的实体。我选择了一个名为二进制数据的属性,并选中允许外部存储框,从我所阅读的内容允许我轻松地坚持在5.x或更新的iOS手机上的文件。我知道我可以编程的应用程序来获取和设置这些属性,但我如何只是存储我的图像和音乐文件在这里?

I added a core data .xc file to my xcode project, and created an entity with attributes. I chose an attribute named "binary data" and checked the box "Allows External Storage," which from what I've read allows me to easily persistently sore files on 5.x or newer iOS phones. I know that I can program the app to get and set these attributes, but how do I just store my images and music files here?

请帮助我与代码/理解。在我看来,我应该能够以某种方式使用核心数据接口来设置一组包含二进制数据属性的实体,它是我的图像和.mp3s,每当我需要显示图片或播放声音时,我可以调用实体及其属性。

Please help with me with code/understanding. It seems to me I should be able to somehow use the core data interface to set up a bunch of entities containing attributes of "binary data" that are my images and .mp3s, and whenever I need to display a pic or play a sound, I could call the entity and its attributes.

感谢您的帮助!

推荐答案

我存储压缩图像(jpegs)与Core Data,它似乎够快了。但是, 100K。

I store compressed images (jpegs) with Core Data and it seems fast enough. But these are compressed to < 100K.

如果您要存储大于100K的项目,您可能只需将文件保存到磁盘,然后执行在iOS上编写文件

If you want to store items bigger than 100K, you might want to just save the file to "disk" doing something along the lines of Write a file on iOS

然后,保存Core Data中的字符串的文件路径。要加载文件,从核心数据获取文件路径,然后读取该文件。

Then, save the file path to a string in Core Data. To load the file, get the file path from core data then read the file in.

我认为苹果建议在100K的临界值。

I think Apple recommends the cutoff at 100K.

这篇关于如何存储许多图像和.mp3文件的核心数据为iphone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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