From cdbadae00214747e9b6a04efe54f9f9860ff04a4 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Tue, 18 Dec 2018 18:44:47 +0900 Subject: [PATCH] added comments to playground --- Playground.playground/Contents.swift | 14 ++++++++++++-- .../contents.xcworkspacedata | 4 ++++ Playground.playground/timeline.xctimeline | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 Playground.playground/playground.xcworkspace/contents.xcworkspacedata create mode 100644 Playground.playground/timeline.xctimeline diff --git a/Playground.playground/Contents.swift b/Playground.playground/Contents.swift index 71a9c40d..ccc21c8a 100644 --- a/Playground.playground/Contents.swift +++ b/Playground.playground/Contents.swift @@ -1,6 +1,7 @@ import UIKit import CoreStore +/// Model Declaration ===== class Animal: CoreStoreObject { let species = Value.Required("species", initial: "Swift") let master = Relationship.ToOne("master") @@ -8,11 +9,13 @@ class Animal: CoreStoreObject { } class Person: CoreStoreObject { - let name = Value.Required("name", initial: "") + let name = Value.Optional("name") let pets = Relationship.ToManyUnordered("pets", inverse: { $0.master }) } +/// ======================= +/// Stack setup =========== let dataStack = DataStack( CoreStoreSchema( modelVersion: "V1", @@ -22,8 +25,11 @@ let dataStack = DataStack( ] ) ) -try dataStack.addStorageAndWait() +try dataStack.addStorageAndWait(SQLiteStore(fileName: "data.sqlite")) +/// ======================= + +/// Transactions ========== dataStack.perform(synchronous: { transaction in let animal = transaction.create(Into()) @@ -34,7 +40,10 @@ dataStack.perform(synchronous: { transaction in person.name .= "John" person.pets.value.insert(animal) }) +/// ======================= + +/// Accessing Objects ===== let bird = dataStack.fetchOne(From().where(\.species == "Sparrow"))! bird.species.value bird.color.value @@ -44,3 +53,4 @@ let owner = bird.master.value! owner.name.value owner.pets.count print(owner) +/// ======================= diff --git a/Playground.playground/playground.xcworkspace/contents.xcworkspacedata b/Playground.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..94b2795e --- /dev/null +++ b/Playground.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,4 @@ + + + diff --git a/Playground.playground/timeline.xctimeline b/Playground.playground/timeline.xctimeline new file mode 100644 index 00000000..bf468afe --- /dev/null +++ b/Playground.playground/timeline.xctimeline @@ -0,0 +1,6 @@ + + + + +