Core Data Codegen Explained!
No more head-scratching
Starting from Xcode8, Apple has added a new Codegen
setting in the Xcode data model editor to help developer manage and maintain their NSManagedObject
subclasses. The Codegen
setting consist of 3 possible configurations:
- Manual/None
- Class Definition
- Category/Extension
These 3 configurations might look a bit confusing at first, and I found out that it is actually quite difficult to find a good article that explain the differences between each configuration and which one to use.
In this article I will go through each configuration and analyse the differences between each of them and I will also give some suggestion on which one you should use and how you should use it for your Core Data project. Without further ado let’s get started!
Manual/None
This is the default behaviour prior to Xcode8 where developer have to manually create and maintain the changes of the NSManagedObject
subclasses.
You can try to create a sample core data project, add a new entity call TestEntity
and generate NSManagedObject
subclass following the step in this link.
If you follow the step correctly, Xcode will generate 2 files: