从AppBundle到CoreData加载图片 [英] Loading images from AppBundle vs. CoreData

查看:271
本文介绍了从AppBundle到CoreData加载图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作目录,其中我收藏视图中的单元格将是带有标签或pdf的图像。将有许多集合,他们自己将是静态的。我希望用户能够保存他喜欢的单元格,并在自己的自定义视图中查看它们。



1)我可以将图像作为数据存储在Core Data 。



2)我可以将图片包含在我的应用程序包中,并在每次我的应用程序启动时加载图片。



我认为从Core Data Store读取数据会给我更多的选择,在构建我的应用程序,以及提供一些性能提升,而不是从应用程序包中读取。真的吗?请记住,大多数数据是静态的。



在我的应用程序包中包含序列化图像和纯数据,这似乎是低效的。 p>

我想我宁愿在商店中使用它,但是它们必须在代码的某个时候从包中加载?



我想知道其他开发者是如何做的。

解决方案

允许外部存储选项的二进制数据,这基本上意味着如果你的文件大于1 MB,它会自动存储在你的数据库之外,你必须做什么不同。在我看来,这是获得两个世界最好的方式,提高性能+自动化+快速查询(虽然它们比平常慢,当你允许外部存储,但仍然比自己做的更快)


I'm making a catalog where the cells in my collection view will be either an image with a label or a pdf. There will be many collections and they themselves will be static. I want the user to be able to save the cells he likes and view them in his own custom view.

1) I could to store the image as data in Core Data.

2) I could just include the image in my App Bundle and load the image from there every time my app starts.

I've got it into to my head that reading data from a Core Data Store would give me more options when building my app as well as offer some boost in performance as opposed to reading it from the app bundle. Is that true? Keeping in mind of course that most of the data is static.

It seems inefficient to have images both serialized images in my app bundle and the pure data as well.

I think I'd rather have it all in the store but they have to be loaded from the bundle at some point in code right?

I'd love to know how other developers do it.

解决方案

Now in Core Data there is an "allows external storage" option for binary data, which basically means if your file is bigger than 1 MB it will be stored automatically outside of your database, and you have to do nothing differently. In my opinion that's the way to get the best of both worlds, increased performance + automatization + fast queries (although they are slower than usual when you allow external storage, but still faster than doing it yourself)

这篇关于从AppBundle到CoreData加载图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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