From 6a4d20b02949c0165ef930e839fbebecec4b053a Mon Sep 17 00:00:00 2001 From: John Estropia Date: Sat, 18 Jul 2015 23:17:20 +0900 Subject: [PATCH] Created TL;DR (a.k.a. sample codes) (markdown) --- TL;DR-(a.k.a.-sample-codes).md | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 TL;DR-(a.k.a.-sample-codes).md diff --git a/TL;DR-(a.k.a.-sample-codes).md b/TL;DR-(a.k.a.-sample-codes).md new file mode 100644 index 0000000..7237c0b --- /dev/null +++ b/TL;DR-(a.k.a.-sample-codes).md @@ -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(.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]] \ No newline at end of file