Master data using UIImage property - use UIImage or NSData?

Use of basic data within a minute. At some point at some point, I decided that any image attributes in subclasses of NSManagedObject should be instances of NSData. I do not remember exactly what informed this decision, but this is what I learned many years ago and have always adhered to since then. When I wanted UIImage, I had a readonly property in my NSManagedObject subclass where the getter would instantiate the UIImage from the data using one of the UIImageRepresentation functions.

Now I'm working on a new project and it seems to me that the Apple PhotoLocations (Core Transformable Attributes) sample application actually uses UIImage for the persisted property. What for? For simplicity, this is certainly simpler, you don't need the UIImageRepresentation call to be made.

I am aware of things like "store in an external record file" etc., my question is not whether or not the images should be in their own entity related to my original entity - is it just or no, I have to use UIImage or NSData as the type of the stored property.

It was difficult to understand what is considered the best practice or which disadvantage is one way or another. Any insight would be appreciated.

+3


source to share


1 answer


I always store data in a format that anyone can read. This simplifies data transfer, use in multiple systems, avoids obsolescence, etc.

When I store an image, I store it in PNG format instead of UIImage. What for?



  • UIImage is subject to change.
  • I can upload it to the server.
  • I may need to read the file on OS X.
  • I might want to make it portable later.

When it comes to data, I only like to think about the past here and now.

+4


source







All Articles