Skip to content
kevindelord edited this page Jul 4, 2016 · 16 revisions

Create a new entry using a new saving context

To create an entity into the local persistent store you need to 'be' in a savingContext.

To do so use the appropriate DKDBManager functions.

DKDBManager.saveWithBlock { (savingContext: NSManagedObjectContext) in

    // Perform saving code here, against the `savingContext` instance.
    // Everything done in this block will occur on a background thread.

	let plane = Plane.crudEntityInContext(savingContext)
	plane?.origin = "London"
    plane?.destination = "Paris"
}

At the end of this execution block, all changes will be saved ( or 'merged' ) into the default context.

After that, a new Plane entity will be available on the main thread within the default context.

Different saving methods

You can call the crudEntityInContext function within every save function of the library.

Please see the Save And Update Entities to learn more about asynchronous and synchronous save.

Child entities or relantionships

In most databases, you need to have relations between objects.

The DKDBManager does not change that logic nor simplifies it.

Please checkout the official Apple documentation.

Clone this wiki locally