Storing Data in Core Data: UIImage

Proceed with caution

Steven Curtis
4 min readFeb 6, 2023
Photo by Luke Chesser on Unsplash

Difficulty: Beginner | Easy | **Normal** | Challenging

You probably shouldn’t be doing this. You probably shouldn’t be doing this.

Core Data can store data, but storing large images like this? Probably you want to use file. But I can see that you **really** want to store UIImage. In that case, let us strap in and get going.

Prerequisites:

Terminology:

Core Data: A framework that allows you to manage the model layer objects in your application. Core Data does this by being an object graph management and persistence framework.

The image to store

In Assets.xcassets I’ve added three Placeholder images.

So…surely I can place this image into core data…right?

This involves adding an image attribute to the core data entity, and give it the type Binary Data.

This Binary Data will, fairly obviously, be the data from an image, and for this I can use the…

--

--