Skip to content

Commit

Permalink
added comments to playground
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnEstropia committed Dec 18, 2018
1 parent 4a28a39 commit cdbadae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Playground.playground/Contents.swift
@@ -1,18 +1,21 @@
import UIKit
import CoreStore

/// Model Declaration =====
class Animal: CoreStoreObject {
let species = Value.Required<String>("species", initial: "Swift")
let master = Relationship.ToOne<Person>("master")
let color = Transformable.Optional<UIColor>("color", initial: .orange)
}

class Person: CoreStoreObject {
let name = Value.Required<String>("name", initial: "")
let name = Value.Optional<String>("name")
let pets = Relationship.ToManyUnordered<Animal>("pets", inverse: { $0.master })
}
/// =======================


/// Stack setup ===========
let dataStack = DataStack(
CoreStoreSchema(
modelVersion: "V1",
Expand All @@ -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<Animal>())
Expand All @@ -34,7 +40,10 @@ dataStack.perform(synchronous: { transaction in
person.name .= "John"
person.pets.value.insert(animal)
})
/// =======================


/// Accessing Objects =====
let bird = dataStack.fetchOne(From<Animal>().where(\.species == "Sparrow"))!
bird.species.value
bird.color.value
Expand All @@ -44,3 +53,4 @@ let owner = bird.master.value!
owner.name.value
owner.pets.count
print(owner)
/// =======================

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Playground.playground/timeline.xctimeline
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>

0 comments on commit cdbadae

Please sign in to comment.