Store image in core data

怎甘沉沦 提交于 2020-01-12 10:00:10

问题


I want to store image for every employee while updating their records. How can I do that?

I have a dictionary storing name, id and department of employees. Now i want the image to be saved together.


回答1:


Core Data supports the "Binary Data" type - When you define a model with a Binary Data field, it creates your model class with an NSData field. You can move an image into the NSData field, and CoreData will save it for you.

You can then use UIImage initWithData: to load the image from the NSData field.

Hope this helps !




回答2:


For strore image as CoreDate attribute need:

  1. Add transformable attribute and set transformer with own class
  2. Implement ImageToDataTransformer

See here for an example http://www.iphonedevsdk.com/forum/181656-post3.html



来源:https://stackoverflow.com/questions/5166830/store-image-in-core-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!