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

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

问题描述

看看 Apple iPhone Core Data Recipes 示例应用程序,它们将图像文件存储在核心数据对象中,这通常不是我认为的明智之举.现在我还要在 3GS 上拍摄故事视频.问题是:在 iPhone 上的 Core Data 中存储图像和电影是否明智?

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?

另外还有加载到内存的添加.显然,Recipes 中使用的设计(即,将图像存储在单独的模型中)允许 Core Data 进行错误处理"(这听起来意味着延迟加载),但我不确定这是否真的如此.

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.

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

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....

推荐答案

视情况而定.CoreData 不仅能够以良好的性能存储大型 blob.最大的问题是:

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

  1. 如果这些 blob 是实体的属性,而这些实体可能并不总是出错,那么您需要小心确保无论何时使用该实体,您都告诉 CD 不要在属性中出错,直到您提出要求.您可以通过将 Blob 隔离在它们自己的实体中来解决这个问题,除非您通过关系访问它,否则这些实体不会出错.

  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.

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

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天全站免登陆