mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-28 12:21:51 +01:00
added comments to playground
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import CoreStore
|
import CoreStore
|
||||||
|
|
||||||
|
/// Model Declaration =====
|
||||||
class Animal: CoreStoreObject {
|
class Animal: CoreStoreObject {
|
||||||
let species = Value.Required<String>("species", initial: "Swift")
|
let species = Value.Required<String>("species", initial: "Swift")
|
||||||
let master = Relationship.ToOne<Person>("master")
|
let master = Relationship.ToOne<Person>("master")
|
||||||
@@ -8,11 +9,13 @@ class Animal: CoreStoreObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Person: CoreStoreObject {
|
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 })
|
let pets = Relationship.ToManyUnordered<Animal>("pets", inverse: { $0.master })
|
||||||
}
|
}
|
||||||
|
/// =======================
|
||||||
|
|
||||||
|
|
||||||
|
/// Stack setup ===========
|
||||||
let dataStack = DataStack(
|
let dataStack = DataStack(
|
||||||
CoreStoreSchema(
|
CoreStoreSchema(
|
||||||
modelVersion: "V1",
|
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
|
dataStack.perform(synchronous: { transaction in
|
||||||
|
|
||||||
let animal = transaction.create(Into<Animal>())
|
let animal = transaction.create(Into<Animal>())
|
||||||
@@ -34,7 +40,10 @@ dataStack.perform(synchronous: { transaction in
|
|||||||
person.name .= "John"
|
person.name .= "John"
|
||||||
person.pets.value.insert(animal)
|
person.pets.value.insert(animal)
|
||||||
})
|
})
|
||||||
|
/// =======================
|
||||||
|
|
||||||
|
|
||||||
|
/// Accessing Objects =====
|
||||||
let bird = dataStack.fetchOne(From<Animal>().where(\.species == "Sparrow"))!
|
let bird = dataStack.fetchOne(From<Animal>().where(\.species == "Sparrow"))!
|
||||||
bird.species.value
|
bird.species.value
|
||||||
bird.color.value
|
bird.color.value
|
||||||
@@ -44,3 +53,4 @@ let owner = bird.master.value!
|
|||||||
owner.name.value
|
owner.name.value
|
||||||
owner.pets.count
|
owner.pets.count
|
||||||
print(owner)
|
print(owner)
|
||||||
|
/// =======================
|
||||||
|
|||||||
4
Playground.playground/playground.xcworkspace/contents.xcworkspacedata
generated
Normal file
4
Playground.playground/playground.xcworkspace/contents.xcworkspacedata
generated
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Workspace
|
||||||
|
version = "1.0">
|
||||||
|
</Workspace>
|
||||||
6
Playground.playground/timeline.xctimeline
Normal file
6
Playground.playground/timeline.xctimeline
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Timeline
|
||||||
|
version = "3.0">
|
||||||
|
<TimelineItems>
|
||||||
|
</TimelineItems>
|
||||||
|
</Timeline>
|
||||||
Reference in New Issue
Block a user