1

I am currently working on an app in which I want to store a UIImage in one of my Core Data entities. I have read that in iOS 5 UIImage now conforms to a protocol called NSCoding, so conversion methods from NSData are no longer necessary. I have set my image attribute to Transformable, and my program works wonderfully when I retrieve the image.

Is this a safe and secure method to store a UIImage that will allow for future below 30 second migrations? Will it be good performance-wise? I have also read about the Binary Data attribute type, that allows files to be stored in the file system, rather than the database. If this is a better alternative, how would one implement it?

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Andrew
  • 479
  • 1
  • 5
  • 13

2 Answers2

1

Migration time depends on the entire database schema and size, not just storing a UIImage. No one can answer that question.

Performance is relative. If you store it externally, it will generally be better performance-wise, because it's not in the database itself, but there are lots of other performance issues, like managing the fault, especially if you store it as a direct attribute as opposed to a relationship. Also, it depends on your usage. No single solution is best for all circumstance.

You must profile your application use cases, and make the decisions that best serve the performance characteristics of your application.

For any non-trivial binary data, you should indeed let Core Data manage that as external data. It's simple. In the data model GUI, check the box that says "Store in External Record File."

Jody Hagins
  • 27,943
  • 6
  • 58
  • 87
0

Sorry, I didn't notice you said that you were already perfectly aware of how to encode images. I would not recommend storing them in the database, but good luck.

Previously: Storing UIImage in Core Data with the new External Storage flag

The comments on that thread about bugs suggest it is still probably a safe idea to just store images on the filesystem yourself.

Community
  • 1
  • 1
binarymochi
  • 113
  • 6