Created TL;DR (a.k.a. sample codes) (markdown)

John Estropia
2015-07-18 23:17:20 +09:00
parent d3815823e7
commit 6a4d20b029

@@ -0,0 +1,74 @@
Setting-up with incremental migration support:
```swift
CoreStore.defaultStack = DataStack(
modelName: "MyStore",
migrationChain: ["MyStore", "MyStoreV2", "MyStoreV3"]
)
```
Adding a store:
```swift
do {
try CoreStore.addSQLiteStore(
fileName: "MyStore.sqlite",
completion: { (result) -> Void in
// ...
}
)
}
catch {
// ...
}
```
Starting transactions:
```swift
CoreStore.beginAsynchronous { (transaction) -> Void in
let person = transaction.create(Into(MyPersonEntity))
person.name = "John Smith"
person.age = 42
transaction.commit { (result) -> Void in
switch result {
case .Success(let hasChanges): print("success!")
case .Failure(let error): print(error)
}
}
}
```
Fetching objects:
```swift
let people = CoreStore.fetchAll(From(MyPersonEntity))
```
```swift
let people = CoreStore.fetchAll(
From(MyPersonEntity),
Where("age > 30"),
OrderBy(.Ascending("name"), .Descending("age")),
Tweak { (fetchRequest) -> Void in
fetchRequest.includesPendingChanges = false
}
)
```
Querying values:
```swift
let maxAge = CoreStore.queryValue(
From(MyPersonEntity),
Select<Int>(.Maximum("age"))
)
```
But really, there's a reason I wrote this huge Wiki. Read up on the details!
Check out the **CoreStoreDemo** app project for sample codes as well!
## Contents
- [[Architecture]]
- [[Setting up]]
- [[Saving and processing transactions]]
- [[Fetching and querying]]
- [[Logging and error handling]]
- [[Observing changes and notifications]]