核心数据保存UIImage [英] Core Data save UIImage
问题描述
如果要保存图像,我在此数据库中有一个核心数据,那么如何保存仅带有URL的图像...
示例
I have a Core Data in this database should I save images, so how can do to save an image that is just takes URL ... Example please
推荐答案
大图像(> 100 kb)不应保存在CoreData中,因为它确实会增加托管对象的内存占用。
Large images (>100 kb) should not be saved in CoreData, as it would really increase your managed object's memory footprint.
对于这些图像,我会将路径保存为字符串或URL,然后在需要时加载图像。
For these images I would save the path in CoreData as a string or an URL and then load the image if you need it.
原则上,您可以保存任何内容如果可以将其归档到 NSData
对象中,则作为CoreData实体中的属性。 CoreData文档中有一些示例,说明如何使用这种技术将 UIColor
保存到数据库中。
In principle you can save anything as an attribute in a CoreData entity if it can be archived into a NSData
object. There are examples in the CoreData documentation of how to save a UIColor
to the database which uses exactly this technique.
查看 CoreRecipes示例代码,其中将图像附加到每个配方。这基本上就是您想要做的事情。
Check out the CoreRecipes sample code in which an image is attached to each recipe. This is basically the same thing you want to do.
这篇关于核心数据保存UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!