Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires committed May 8, 2016
1 parent 86aa117 commit 14b5cee
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This library aims to do the following:
* Provide better interoperability with Swift
* Harness Swift features and enforce Swift paradigms
* Bring functional paradigms to Core Data
* Make Core Data more *Swifty*
* Simplify the processes of standing up the Core Data stack
* Aid in testing your Core Data models
* Reduce the boilerplate involved with Core Data
Expand Down Expand Up @@ -74,7 +75,7 @@ let model = CoreDataModel(name: "MyModel", bundle: bundle)
let factory = CoreDataStackFactory(model: model)

let stack: CoreDataStack?
factory.createStackInBackground { (result: CoreDataStackResult) in
factory.createStack { (result: StackResult) in
switch result {
case .Success(let s):
stack = s
Expand All @@ -90,7 +91,17 @@ factory.createStackInBackground { (result: CoreDataStackResult) in
````swift
let inMemoryModel = CoreDataModel(name: myName, bundle: myBundle, storeType: .InMemory)
let factory = CoreDataStackFactory(model: inMemoryModel)
let stack = factory.createStack()

let stack: CoreDataStack?
factory.createStack { (result: StackResult) in
switch result {
case .Success(let s):
stack = s

case .Failure(let e):
print("Error: \(e)")
}
}
````

#### Saving a managed object context
Expand All @@ -113,7 +124,7 @@ saveContext(stack.mainContext) { result in
let bundle = NSBundle(identifier: "com.MyApp.MyModelFramework")!
let model = CoreDataModel(name: "MyModel", bundle: bundle)
do {
try model.removeExistingModelStore()
try model.removeExistingStore()
} catch {
print("Error: \(error)")
}
Expand All @@ -126,7 +137,7 @@ let bundle = NSBundle(identifier: "com.MyApp.MyModelFramework")!
let model = CoreDataModel(name: "MyModel", bundle: bundle)
if model.needsMigration {
do {
try migrate(model)
try model.migrate()
} catch {
print("Failed to migrate model: \(error)")
}
Expand All @@ -136,8 +147,11 @@ if model.needsMigration {
#### Using child contexts

````swift
// Create a background queue child context from the main queue context
let childContext = stack.childContext()
// Create a main queue child context from the main context
let childContext = stack.childContext(concurrencyType: .MainQueueConcurrencyType)

// Create a background queue child context from the background context
let childContext = stack.childContext(concurrencyType: .PrivateQueueConcurrencyType)
````

#### Fetching
Expand All @@ -149,7 +163,7 @@ let request = FetchRequest<MyModel>(entity: entity)

var results = [MyModel]()
do {
results = try fetch(request: request, inContext: context)
results = try stack.mainContext.fetch(request: request)
}
catch {
print("Fetch error: \(error)")
Expand All @@ -163,7 +177,7 @@ print("Results = \(results)")
````swift
let objects: [MyModel] = /* array of MyModel objects */

deleteObjects(objects, inContext: context)
stack.mainContext.delete(objects: objects)

// Commit changes to remove objects from store
saveContext(context)
Expand Down

0 comments on commit 14b5cee

Please sign in to comment.