Latest 1.1.0
Homepage https://github.com/kevindelord/DKDBManager
License MIT
Platforms ios 8.0, requires ARC
Dependencies MagicalRecord
Frameworks CoreData
Authors

Build Status
codecov.io
Cocoapods
Carthage compatible
License
Platform

Concept

DKDBManager is a simple, yet very useful, CRUD manager around Magical Record.

It implements a logic around the database that helps the developer to manage his entities and let him focus on other things than only data management.

The main concept is to import JSON dictionaries representing entities into the database.

After some configuration on your model classes, only one single function is needed to create, read, update or delete your entities!

Documentation

The complete documentation is available on CocoaDocs.

More over, the Wiki contains all kind of information and details about the different logics of the library.

Quick overview

With the DKDBManager and MagicalRecord you can easily create, update or delete entities.

To do so you need to be in a savingContext and 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.

Or you could CRUD an entity by using a JSON structure:

let planeJSON = ["origin":"Paris", "destination":"London"]
Plane.crudEntityWithDictionary(planeJSON, inContext: savingContext, completion: { (entity: AnyObject?, state: DKDBManagedObjectState) in

    // The CRUDed plane is referenced in the `entity`.
    // Its actual state is described as follow:
    switch state {
    case .Create:   // The entity has been created, it's all fresh new.
    case .Update:   // The entity has been updated, its attributes changed.
    case .Save:     // The entity has been saved, nothing happened.
    case .Delete:   // The entity has been removed.
    }
})

The state variable describes what happened to the entity.

The implementation of other functions is also recommended such as the one to update the current entity with a given dictionary.

Without this function the attributes of the entity will never be set nor updated.

The given dictionary object is the same one that has been used to start the CRUD process.

override func updateWithDictionary(dictionary: [NSObject : AnyObject]?, inContext savingContext: NSManagedObjectContext) {
    super.updateWithDictionary(dictionary, inContext: savingContext)
    // Update attributes
    self.origin         = GET_STRING(dictionary, "origin")
    self.destination    = GET_STRING(dictionary, "destination")
}

Read more in the Wiki! :bowtie:

Try it out!

Checkout the example project:

$> pod try DKDBManager

Author

kevindelord, [email protected]

Latest podspec

{
    "name": "DKDBManager",
    "version": "1.1.0",
    "summary": "Database manager to use around MagicalRecord to provide a complete CRUD logic for your entities.",
    "homepage": "https://github.com/kevindelord/DKDBManager",
    "license": "MIT",
    "authors": {
        "kevindelord": "[email protected]"
    },
    "source": {
        "git": "https://github.com/kevindelord/DKDBManager.git",
        "tag": "1.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "frameworks": "CoreData",
    "source_files": "DKDBManager/*",
    "dependencies": {
        "MagicalRecord": [
            "~> 2.3.2"
        ]
    },
    "prefix_header_contents": "#import n#import "
}

Pin It on Pinterest

Share This