简体   繁体   English

核心数据,将图像存储在字典中

[英]core data, storing images in a dictionary

I have an app that feature "pages". 我有一个具有“页面”功能的应用程序。 Each page can have n number of images, depending on user preference. 每个页面可以包含n张图像,具体取决于用户的偏好。 To store the images and associate the image with the correct view etc, I am building a dictionary for each image, then storing that dictionary in an array of image dictionaries, which I save to core data as binary data. 为了存储图像并将图像与正确的视图等相关联,我为每个图像构建一个字典,然后将该字典存储在图像字典数组中,并将其保存为二进制数据作为核心数据。 I am storing the image itself as an object in the dictionary, like below. 我将图像本身作为对象存储在字典中,如下所示。 Is this an efficient and safe way to do this? 这是一种有效且安全的方法吗? Seems to work ok... 似乎可以正常工作...

imageDictionay = [NSMutableDictionary dictionaryWithObjectsAndKeys:image, @"image", imageTag, @"tag", imageTransformString, @"transform", nil];

That way will certainly work, but I would personally create another entity for ImageInfo like so: 这样肯定可以,但是我个人会为ImageInfo创建另一个实体,如下所示:

图形编辑器

标准编辑器

If you are going to have a dictionary with the same three keys, it makes more sense to me to have an entity with those three attributes. 如果您要使用具有相同三个键的字典,那么拥有一个具有这三个属性的实体对我来说更有意义。

Also, if you are really worried about performance, you could also write the image to disk and just put a string in Core Data to tell you where the image is stored. 另外,如果您真的担心性能,还可以将映像写入磁盘,然后在Core Data中放置一个字符串以告诉您映像的存储位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM