Programmatically using CoreData
by Thizzer

Apple’s CoreData provides an easy-to-use mechanism to store data and objects in your iOS and OSX Apps. Using the .xcdatamodeld file you can predefine your model and using that you can generate NSManagedObject subclasses to allow easy interaction with your database. CoreData also allows for versioning of your datamodel so that you have to do the least manual conversion possible when making changes to it.


Now in general I am not a fan of defining a datamodel in a separate file an managing my objects for interaction with that model in a separate place. I am a fan of skipping the file and doing stuff ‘programmatically’.


In this article I will explain how to programatically create and manage CoreData storage in Objective-C. Later I will also try to add a Swift variant.