Getting Started

Start by creating a project. For full source code click here


Xcode comes with a beautiful visualization for our CoreData file called xcodeProjectName.xcdatamodeld . Now let’s add a Person entity by clicking on the + and add the Attributes exactly like below.

Also, click Person entity → Data Model Inspector → Codegen, and change it to Manual/None. As we will customize this ourselves which is a very common practice.


Core Data allows us to store integers, booleans, strings, UUID, date, etc. but sometimes we want to store a specific data type like UIColor, UIImage, our own class, struct, or enum, and even arrays, but that is simply not an option in Attribute’s Type.

Say hello to Transformable property type which allows us to store custom data types as an object of the declared attribute for a record of an Entity. The only requirement is that our custom type should conform to NSCoding or we need to provide a custom value transformer.

_When you declare a property as _[_Transformable_](,Transformable%20properties,by%20creating%20a%20Transformable%20property.)_ Core Data converts your custom data type into binary _[_Data_](,Transformable%20properties,by%20creating%20a%20Transformable%20property.)_ when it is saved to the persistent store and converts it back to your custom data type when fetched from the store. It does this through a value transformer._

#core-data #swift #swift-programming #uicolor

Saving UIColor and Array in CoreData Using Transformable
20.50 GEEK