1min read

Winning the war on CoreData Boilerplate code!

As wonderful as CoreData is, most tasks require a set of repetitive / boilerplate method calls. The result is code duplication, and reduced readability. A different challenge lies in implementing Thread Confinement as described in [Concurrency with Core Data]( ac/#documentation/cocoa/conceptual/coredata/Articles/cdConcurrency.html).

We have just released a set of helper tools, to solve these problems. Check out: PLCodeDataUtils on Github.

Firstly, you will see a category on NSManagedObjectContext implementing common data access and manipulation methods. “Create or update a entity?” A common issue that would normally require you to perform a fetch manually. Instead you can now use our helper method insertOrFetchEntityWithName:predicate: to solve this!

Secondly, you can use PLContextHolder whenever you need to perform any CoreData task on secondary threads. It handles the creation and merging of the context for you.

Finally, there’s PLEntityObservatory which tracks updates on selected entities. So now there’s no need to use a NSFetchedResultsController.

Antoni Kędracki

Principal Software Engineer

Did you enjoy the read?

If you have any questions, don’t hesitate to ask!