Recently I attended a Core Data workshop given by Marcus Zarra at iOSDevUK. It was brilliant. He threatened to talk and talk until we all passed out, which would have been great, except I had to catch the train home. If you are at all interested in Core Data (and if you’re reading this, I have to assume you are) then listening to the man who literally wrote the book on it is an opportunity you shouldn’t miss.
One of the things he mentioned was the “Core Data Stack”, the term typically used to refer to the
NSManagedObjectContext that make up the heart of Core Data.
“You can set this up in five lines of code”
Talking to others in the room during the break, it seemed that a lot of people were sticking (or stuck with) with Apple’s template code, which is considerably more than 5 lines and, to add insult to injury, also lives in the app delegate.
While I’m waiting for Marcus’ book to arrive, let’s try and set up a core data stack in five lines of code and see what happens. Note that none of this is code we were shown in the workshop, and is not endorsed by Marcus Zarra in any way. By the end of the post, I’ll have explained how to add a fully functional Core Data stack to your project.