Core Data Codegen Explained!

Image for post
Image for post
Image for post
Image for post
Codegen configuration available in Xcode8.

Manual/None

TestEntity+CoreDataClass.swift
TestEntity+CoreDataProperties.swift
Image for post
Image for post
TestEntity created for sample core data project.
let _ = TestEntity(context: persistentContainer.viewContext)

Class Definition

Image for post
Image for post
Compile error after deleted the NSManagedObject subclass.
Image for post
Image for post
Select “Jump to Definition” to see auto generated NSManagedObject subclass.
Image for post
Image for post
Select “Show in Finder” to see the physical files in finder

You should never edit the auto generated files as they are managed by Xcode, thus they will be overwritten by Xcode every time you build your project.

Category/Extension

Which One to Use?

Class Definition

Category/Extension

TestEntity+CoreDataClass.swift
let entity = TestEntity(context: persistentContainer.viewContext)
entity.image = UIImage(named: "sample-image")!

Manual/None

TestEntity+CoreDataProperties.swift
TestEntity+CoreDataClass.swift

Final Thoughts

Image for post
Image for post
kahseng.lee123@gmail.com

Written by

https://swiftsenpai.com | iOS developer since 2011 | Swift Lover | Music Addict | Anime Fan | Part-time Backpacker

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store