在iPhone上的Core Data中存储大型(例如图像/电影)文件 [英] Storing large (e.g. image/movie) files in Core Data on the iPhone

查看:157
本文介绍了在iPhone上的Core Data中存储大型(例如图像/电影)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看苹果iPhone Core Data Recipes示例应用程序,他们将图像文件存储在核心数据对象中,这不是我通常认为的明智之举。现在我也要在3GS上捕获视频的故事。问题是:在iPhone上的Core Data中存储图像,然后进一步存储电影是否明智?



此外还有加载到内存中。显然,在Recipes中使用的设计(即,将图像存储在单独的模型中)允许Core Data做错误(这听起来像是意味着延迟加载),但我不知道这是否真的真的。

在这里查看: http://developer.apple.com/iPhone/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html#//apple_ref/doc/ uid / TP40003468-SW5 似乎通用的Cocoa建议是使用单独的文件....

解决方案

这取决于。 CoreData不仅能够存储具有良好性能的大型blob。大问题是:


  1. 如果这些blob是实体的属性,可能不总是在你的错误,你需要小心,你使用你告诉CD不要在属性中出错的实体,直到你问。

  2. 您的持久存储是一个单片文件,它是一个单独的文件,意味着如果其中的任何内容更改整个事情需要在备份期间复制。这通常会增加手机在与iTunes同步时所需的时间,因为您更改了一些元数据,现在必须复制每个图像。



    第一个问题通常不是很大,你只需要小心。第二个不是一个问题,如果数据是有效的只读,但如果你有一个几百兆字节的数据在持久存储它可以是一个非常糟糕的用户体验。



Looking at the Apple iPhone Core Data Recipes sample app, they store image files in core data objects, which is not something I would normally think would be wise. Now I'm going to be also stories captured video on the 3GS. The question is: is it wise to store images, and then furthermore, movies, in Core Data on the iPhone?

In addition there is the addition of loading into memory. Apparently the design used in Recipes (i.e., storing the image in a separate model) allows Core Data to do "faulting" (which sounds like it means lazy loading), but I'm not sure if that's really true.

Looking here: http://developer.apple.com/iPhone/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html#//apple_ref/doc/uid/TP40003468-SW5 it seems that the generic Cocoa advice is to use separate files....

解决方案

It depends. CoreData is more than capable of storing large blobs with good performance. The big gotchas are:

  1. If those blobs are properties of entities that might not always be faulted in you need to be careful to make sure whenever you use the entity you tell CD not to fault in properties until you ask. You can work around that by isolating the blobs in their own entities, which will not get faulted until you access it through the relationship.
  2. Your persistent store is one monolithic file, which means if anything in it changes the whole thing needs to be copied during backups. This often increases the time it takes for the phone to backup while it is synching with iTunes, because you changed some metadata and now it has to copy every image.

    The first issue is usually not a big deal, you just need to be careful. The second is not an issue if the data is effectively readonly, but if you have a couple hundred megabytes of data in your persistent store it can be a pretty awful user experience.

这篇关于在iPhone上的Core Data中存储大型(例如图像/电影)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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