Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Commit 199aa25

Browse files
committed
Updated readme
1 parent 7b48d18 commit 199aa25

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

CoreDataKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "CoreDataKit"
3-
s.version = "0.7.0"
3+
s.version = "0.8.0"
44
s.license = "MIT"
55

66
s.summary = "CoreDataKit makes common operations on objects and importing into CoreData a breeze."

README.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ source 'https://github.com/CocoaPods/Specs.git'
1313
platform :ios, '8.0'
1414
use_frameworks!
1515

16-
pod 'CoreDataKit', '~> 0.6'
16+
pod 'CoreDataKit', '~> 0.8'
1717
```
1818

1919
## Usage
@@ -33,32 +33,35 @@ For CoreDataKit to be able to use your NSManagedObject subclass, such as Car in
3333
```swift
3434
class Car: NSManagedObject, NamedManagedObject {
3535

36-
static var entityName = "Car" //corresponding to your Enity name in your xcdatamodeld
36+
static var entityName = "Car" // corresponding to your Entity name in your xcdatamodeld
3737

3838
@NSManaged var color: String
3939
@NSManaged var model: String
40-
4140
}
4241

4342
```
4443

4544
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:
4645
```swift
4746
CDK.performBlockOnBackgroundContext({ context in
48-
if let car = context.create(Car.self).value() {
49-
car.color = "Hammerhead Silver"
50-
car.model = "Aston Martin DB9"
51-
}
52-
53-
return .SaveToPersistentStore
54-
}, completionHandler: { result, _ in
55-
switch result {
56-
case .Success:
57-
println("Car saved, time to update the interface!")
58-
59-
case let .Failure(error):
60-
println("Saving Harvey Specters car failed with error: \(error)")
61-
}
47+
do {
48+
let car = try context.create(Car.self)
49+
car.color = "Hammerhead Silver"
50+
car.model = "Aston Martin DB9"
51+
52+
return .SaveToPersistentStore
53+
}
54+
catch {
55+
return .DoNothing
56+
}
57+
}, completionHandler: { result in
58+
do {
59+
try result()
60+
print("Car saved, time to update the interface!")
61+
}
62+
catch {
63+
print("Saving Harvey Specters car failed with error: \(error)")
64+
}
6265
})
6366
```
6467

@@ -67,19 +70,25 @@ CDK.performBlockOnBackgroundContext({ context in
6770
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/develop/extensions/PromissumExtensions/CoreDataKit%2BPromise.swift) extension, the example from above can be rewritten as such:
6871
```swift
6972
let createPromise = CDK.performBlockOnBackgroundContextPromise { context in
70-
if let car = context.create(Car.self).value() {
71-
car.color = "Hammerhead Silver"
72-
car.model = "Aston Martin DB9"
73-
}
74-
75-
return .SaveToPersistentStore
73+
do {
74+
let car = try context.create(Car.self)
75+
car.color = "Hammerhead Silver"
76+
car.model = "Aston Martin DB9"
77+
78+
return .SaveToPersistentStore
79+
}
80+
catch {
81+
return .DoNothing
82+
}
7683
}
7784

78-
createPromise.then { _ in
79-
println("Car saved, time to update the interface!")
80-
}.catch { error in
81-
println("Saving Harvey Specters car failed with error: \(error)")
82-
}
85+
createPromise
86+
.then { _ in
87+
print("Car saved, time to update the interface!")
88+
}
89+
.trap { error in
90+
print("Saving Harvey Specters car failed with error: \(error)")
91+
}
8392
```
8493

8594
## Contributing

0 commit comments

Comments
 (0)