<commit_before># CoreDataKit

**CoreDataKit takes care of the hard and verbose parts of CoreData. It manages child contexts for you and helps to easily fetch, create and delete objects.**

> *CoreData:* object graph management solution, including persistence. *Kit:* set of equipment needed for a specific purpose.

## Installation

[CocoaPods](http://cocoapods.org) is the advised way to include CoreDataKit into your project. A basic [Podfile](http://cocoapods.org/#get_started) including CoreDataKit would look like this:

```
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'CoreDataKit', '~> 0.4'
```

## Usage

The most basic and most used variant to setup a stack backed by an automigrating SQLite store is this:
```
// Initialize CoreData stack
if let persistentStoreCoordinator = NSPersistentStoreCoordinator(automigrating: true) {
  CoreDataKit.sharedStack = CoreDataStack(persistentStoreCoordinator: persistentStoreCoordinator)
}
```

From here you are able to use the shared stack. For example to create and save an entity, this example performs a block an a background context, saves it to the persistent store and executes a completion handler:
```
CoreDataKit.performBlockOnBackgroundContext({ context in
	if let car = context.create(Car.self).value() {
		car.color = "Hammerhead Silver"
		car.model = "Aston Martin DB9"
	}

	return .SaveToPersistentStore
}, completionHandler: { result, _ in
    switch result {
    case .Success:
    	println("Car saved, time to update the interface!")
      
    case let .Failure(error):
      	println("Saving Harvey Specters car failed with error: \(error)")
    }
})
```

### Using promises

If you prefer using promises, instead of the callback style of this library, you can use the  [Promissum](https://github.com/tomlokhorst/Promissum) library with CoreDataKit. Using the [CoreDataKit+Promise](https://github.com/tomlokhorst/Promissum/blob/master/extensions/PromissumExtensions/CoreDataKit%2BPromise.swift) extension, the example from above can be rewritten as such:
```
let createPromise = CoreDataKit.performBlockOnBackgroundContextPromise { context in
	if let car = context.create(Car.self).value() {
		car.color = "Hammerhead Silver"
		car.model = "Aston Martin DB9"
	}

	return .SaveToPersistentStore
}

createPromise.then { _ in
	println("Car saved, time to update the interface!")
}.catch { error in
	println("Saving Harvey Specters car failed with error: \(error)")
}
```


## Contributing

We'll love contributions, please report bugs in the issue tracker, create pull request (please branch of `develop`) and suggest new great features (also in the issue tracker).

## License & Credits<commit_msg>Update readme to refer to the new CDK class<commit_after># CoreDataKit

**CoreDataKit takes care of the hard and verbose parts of CoreData. It manages child contexts for you and helps to easily fetch, create and delete objects.**

> *CoreData:* object graph management solution, including persistence. *Kit:* set of equipment needed for a specific purpose.

## Installation

[CocoaPods](http://cocoapods.org) is the advised way to include CoreDataKit into your project. A basic [Podfile](http://cocoapods.org/#get_started) including CoreDataKit would look like this:

```
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'CoreDataKit', '~> 0.4'
```

## Usage

The most basic and most used variant to setup a stack backed by an automigrating SQLite store is this:
```
// Initialize CoreData stack
if let persistentStoreCoordinator = NSPersistentStoreCoordinator(automigrating: true) {
  CDK.sharedStack = CoreDataStack(persistentStoreCoordinator: persistentStoreCoordinator)
}
```

From here you are able to use the shared stack. For example to create and save an entity, this example performs a block an a background context, saves it to the persistent store and executes a completion handler:
```
CDK.performBlockOnBackgroundContext({ context in
	if let car = context.create(Car.self).value() {
		car.color = "Hammerhead Silver"
		car.model = "Aston Martin DB9"
	}

	return .SaveToPersistentStore
}, completionHandler: { result, _ in
    switch result {
    case .Success:
    	println("Car saved, time to update the interface!")
      
    case let .Failure(error):
      	println("Saving Harvey Specters car failed with error: \(error)")
    }
})
```

### Using promises

If you prefer using promises, instead of the callback style of this library, you can use the  [Promissum](https://github.com/tomlokhorst/Promissum) library with CoreDataKit. Using the [CoreDataKit+Promise](https://github.com/tomlokhorst/Promissum/blob/master/extensions/PromissumExtensions/CoreDataKit%2BPromise.swift) extension, the example from above can be rewritten as such:
```
let createPromise = CDK.performBlockOnBackgroundContextPromise { context in
	if let car = context.create(Car.self).value() {
		car.color = "Hammerhead Silver"
		car.model = "Aston Martin DB9"
	}

	return .SaveToPersistentStore
}

createPromise.then { _ in
	println("Car saved, time to update the interface!")
}.catch { error in
	println("Saving Harvey Specters car failed with error: \(error)")
}
```

## Contributing

We'll love contributions, please report bugs in the issue tracker, create pull request (please branch of `develop`) and suggest new great features (also in the issue tracker).

## License & Credits
{'fraction_non_alphanumeric': 0.09400921658986175, 'fraction_numerical': 0.0025806451612903226, 'mean_word_length': 4.7846481876332625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '584458', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1521, 'n_words': 583}