Latest 1.0.0
Homepage https://github.com/metova/DataManager
License MIT
Platforms ios 8.0, osx 10.9, watchos 2.0, tvos 9.0
Frameworks CoreData
Authors

DataManager

Build Status
CocoaPods Compatible
Documentation
Coverage Status
Platform
Twitter

DataManager is a lightweight Core Data utility. It is not a replacement/wrapper for Core Data. Here are some of the highlights:

  • Encapsulates the boilerplate associated with setting up the Core Data stack.
  • Sets up the stack with a private NSPrivateQueueConcurrencyType context as the root context with a public NSMainQueueConcurrencyType child context. This setup allows for asynchronous saves to disk.
  • Provides Swift-friendly convenience fetching methods that make use of generics to prevent you from having to handle downcasting from NSManagedObject to the entity’s class every time you perform a fetch.

Requirements

  • Swift 3.0

Installation

DataManager is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'DataManager'

If you would like to test a beta version of DataManager, you can install the latest from develop:

pod 'DataManager', :git => 'https://github.com/metova/DataManager.git', :branch => 'develop'

Usage

Setup

When your app is launched, set up DataManager with the data model name and a name for the persistent store file:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    DataManager.setUp(withDataModelName: "MyApp", bundle: Bundle.main, persistentStoreName: "MyApp")

    /* ... */

    return true
}

This won’t set up the Core Data stack right away. The stack is lazy loaded when DataManager.mainContext is first used.

Fetching

DataManager uses generics so you don’t have to worry about casting the NSManagedObject results to the entity’s class every time you perform a fetch. For example, the type of olderUsers below is [User].

let predicate = NSPredicate(format: "(#keyPath(Person.birthDate)) < %@", someDate)
let olderUsers = DataManager.fetchObjects(entity: User.self, predicate: predicate, context: DataManager.mainContext)

Deleting

DataManager.delete([user1, user2], in: DataManager.mainContext)

Saving

DataManager.persist(synchronously: false)

Child Contexts

let backgroundContext = DataManager.createChildContext(withParent: DataManager.mainContext)

backgroundContext.perform {
    /* Do heavy lifting in the background */
}

Credits

DataManager is owned and maintained by Metova Inc.

Contributors

License

DataManager is available under the MIT license. See the LICENSE file for more info.

Alternatives

Latest podspec

{
    "name": "DataManager",
    "version": "1.0.0",
    "summary": "DataManager is a small utility class that helps you manage Core Data.",
    "description": "DataManager takes care of Core Data boilerplate code for you. It handles setting up the Core Data stack with support for asynchronous saves. It also includes a few simple fetch and deletion methods.",
    "homepage": "https://github.com/metova/DataManager",
    "license": "MIT",
    "authors": {
        "Logan Gauthier": "[email protected]"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/metova/DataManager.git",
        "tag": "1.0.0"
    },
    "source_files": "Sources/*.swift",
    "frameworks": "CoreData"
}

Pin It on Pinterest

Share This