使用新的外部存储标志将 UIImage 存储在 Core Data 中 [英] Storing UIImage in Core Data with the new External Storage flag

查看:16
本文介绍了使用新的外部存储标志将 UIImage 存储在 Core Data 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 UIImage 在核心数据中的存储已经讨论了很多,比如 此处,但那是 ios5 之前的版本.现在我们有了外部存储标志,你们认为将 UIImage 直接存储在实体中,作为一个单独的实体,还是仍然在磁盘上是个好主意?

I know that the storing of UIImage's in core data has been discussed a lot, such as here, but that was pre-ios5. Now that we have the external storage flag, do you guys think it would be a fine idea to store UIImage's directly in the entity, as a separate entity, or still on the disk?

此处是解释外部存储选项的来源.

Here is a source explaining the external storage option.

推荐答案

iOS 5.0 核心数据发布说明

启用后,Core Data 会根据每个值启发式地决定,如果它应该将数据直接保存在数据库中或将 URI 存储到它为您管理的单独文件.您不能根据如果使用此选项,则为二进制数据属性的内容.

When enabled, Core Data heuristically decides on a per-value basis if it should save the data directly in the database or store a URI to a separate file which it manages for you. You cannot query based on the contents of a binary data property if you use this option.

从您的链接 外部二进制数据来看,启发式似乎是

And from your link External Binary Data, the heuristic seems to be

小于 1MB 的对象存储在数据库中.为了更大的对象,创建一个外部文件和数据库只存储对它的引用.

Objects that are smaller than 1MB are stored in the database. For objects that are larger, an external file is created and the database just stores a reference to it.

因此以下建议仍然有效:CoreData : store图像到数据库还是不?

So the following advice is still valid: CoreData : store images to DB or not?

  • <100kb 与相关数据存储在同一张表中
  • <1mb 存储在通过关系附加的单独表中,以避免不必要的加载

1mb 存储在磁盘上并在核心数据中引用它

1mb store on disk and reference it inside of Core Data

该标志将 Core Data 设置为遵循该建议并自动将大于 1MB 的图像存储为单独的磁盘文件.

The flag sets Core Data to follow that advice and automatically store images >1MB as a separate disk file.

这篇关于使用新的外部存储标志将 UIImage 存储在 Core Data 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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