Have you forgot to select the use Core Data checkmark or have an application where it doesn’t allow you to select it at all? Don’t worry, you can still add Core Data implementation in your app.

Adding Core Data Model

Add a new file, then scroll down to the Data Model. Select and click through. This creates a file with a xcdatamodeld which is where you can use the UI to create your entities.

Added Entities

You can add an entity by selecting ‘Add Entity’ at the bottom of the editor. I added two entities; Animal and Person. I also added attributes to each one; for Animal, I added name and type with String data types. The attributes can be added by clicking on the ‘+’ sign in the attributes section. The data types can be altered by just clicking on the data type and selecting on the drop down.

Create NSManagedObject Subclass

You can now map these entities to classes deriving from the NSManagedObject class. This will make it easier for reference the entities and utilize the Core Data framework in code. You can manually do this or use Xcode’s features. To use this feature, go to Editor -> Create NSManagedObject Subclass…

Select Model   Select Entities

Select the data model, the entities to generate, and then create.

NSManaged Object Classes

Once done, you will see these auto-generated classes show up; one for setting up properties and the other is for operations. This is something you will often see in the object-oriented world. Now you have successfully added the Core Data model, added entities to that model, and created NSManagedObject classes.

Your next challenge will be implementing your own Core Data Stack, can you do that?

Back To Top