I have an application where I allow the user to add an image for their account.
I wish to know how to store an image (obtained from the camera or photo library) using Core Data, as I may offer a backup facility for the user and would be looking to transfer the image data to a server.
I have come across the design suggestion of creating an Image
model object and creating a 1-to-1 relationship with the User
model object (so that the associated Image object is not called up unless required). However, I am unsure how to practically store the image and whether this is potentially fatal in terms of performance.
I would be grateful for any advice on the approach and pitfalls from anyone who has attempted this.
The rule for storing image data in Core Data is as follows:
1 mb store on disk and reference the path in your Core Data store.
You can use the transformable data type to store the NSImage directly into Core Data. In fact you can use the transformable data type to store anything that implements the NSCoder protocol.
Personally I would not convert it to a CGImageRef as you can lose a lot of information that way.