简体   繁体   中英

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

图形编辑器

标准编辑器

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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