From 5febf2542d9a31d19ff623c66278af1efcd83ef1 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 14 Dec 2018 19:28:55 +0900 Subject: [PATCH] added playgrounds just to show off --- CoreStore.xcodeproj/project.pbxproj | 2 + Playground.playground/Contents.swift | 46 +++++++++++++++++++++ Playground.playground/contents.xcplayground | 4 ++ 3 files changed, 52 insertions(+) create mode 100644 Playground.playground/Contents.swift create mode 100644 Playground.playground/contents.xcplayground diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index f129a82..e1916c1 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -955,6 +955,7 @@ B5E84F351AFF85470064E85B /* NSManagedObjectContext+Querying.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+Querying.swift"; sourceTree = ""; }; B5E84F401AFF8CCD0064E85B /* TypeErasedClauses.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeErasedClauses.swift; sourceTree = ""; }; B5E8A71F21C1015300EF006A /* CoreStoreObject+Observing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreStoreObject+Observing.swift"; sourceTree = ""; }; + B5E8A72621C3B85000EF006A /* Playground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Playground.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; B5ECDBDE1CA6BB2B00C7F112 /* CSBaseDataTransaction+Querying.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CSBaseDataTransaction+Querying.swift"; sourceTree = ""; }; B5ECDBE41CA6BEA300C7F112 /* CSClauseTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSClauseTypes.swift; sourceTree = ""; }; B5ECDBEB1CA6BF2000C7F112 /* CSFrom.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSFrom.swift; sourceTree = ""; }; @@ -1045,6 +1046,7 @@ 2F03A52619C5C6DA005002A5 = { isa = PBXGroup; children = ( + B5E8A72621C3B85000EF006A /* Playground.playground */, 2F291E3119C6D4D3007AF63F /* Frameworks */, 2F03A53219C5C6DA005002A5 /* Sources */, 2F03A53C19C5C6DA005002A5 /* CoreStoreTests */, diff --git a/Playground.playground/Contents.swift b/Playground.playground/Contents.swift new file mode 100644 index 0000000..71a9c40 --- /dev/null +++ b/Playground.playground/Contents.swift @@ -0,0 +1,46 @@ +import UIKit +import CoreStore + +class Animal: CoreStoreObject { + let species = Value.Required("species", initial: "Swift") + let master = Relationship.ToOne("master") + let color = Transformable.Optional("color", initial: .orange) +} + +class Person: CoreStoreObject { + let name = Value.Required("name", initial: "") + let pets = Relationship.ToManyUnordered("pets", inverse: { $0.master }) +} + + +let dataStack = DataStack( + CoreStoreSchema( + modelVersion: "V1", + entities: [ + Entity("Animal"), + Entity("Person") + ] + ) +) +try dataStack.addStorageAndWait() + +dataStack.perform(synchronous: { transaction in + + let animal = transaction.create(Into()) + animal.species .= "Sparrow" + animal.color .= .yellow + + let person = transaction.create(Into()) + person.name .= "John" + person.pets.value.insert(animal) +}) + +let bird = dataStack.fetchOne(From().where(\.species == "Sparrow"))! +bird.species.value +bird.color.value +print(bird) + +let owner = bird.master.value! +owner.name.value +owner.pets.count +print(owner) diff --git a/Playground.playground/contents.xcplayground b/Playground.playground/contents.xcplayground new file mode 100644 index 0000000..9f5f2f4 --- /dev/null +++ b/Playground.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file