-
Notifications
You must be signed in to change notification settings - Fork 5
Create Entities
kevindelord edited this page Jul 4, 2016
·
16 revisions
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.
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.
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.