From f985828f3b08e26f420903a6e968fcfd7c6317f5 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Tue, 17 Nov 2020 18:14:23 +0900 Subject: [PATCH] cleanup --- CoreStoreTests/DynamicModelTests.swift | 13 -------- CoreStoreTests/WhereTests.swift | 7 ---- .../⭐️Modern.ColorsDemo.SwiftUI.ListView.swift | 3 +- Sources/EnvironmentValues+DataSources.swift | 1 - Sources/ObjectPublisher.swift | 16 ++++------ Sources/ObjectSnapshot.swift | 32 +++++++++++-------- 6 files changed, 27 insertions(+), 45 deletions(-) diff --git a/CoreStoreTests/DynamicModelTests.swift b/CoreStoreTests/DynamicModelTests.swift index 7960edd..767f9b7 100644 --- a/CoreStoreTests/DynamicModelTests.swift +++ b/CoreStoreTests/DynamicModelTests.swift @@ -290,19 +290,6 @@ class DynamicModelTests: BaseTestDataTestCase { } } -// #if swift(>=5.1) -// -// let dogKeyPathBuilder = Dog.keyPathBuilder() -// XCTAssertEqual(dogKeyPathBuilder.species.keyPathString, "SELF.species") -// XCTAssertEqual(dogKeyPathBuilder.master.title.keyPathString, "SELF.master.title") -// let a = dogKeyPathBuilder.master -// let b = dogKeyPathBuilder.master.spouse -// let c = dogKeyPathBuilder.master.spouse.pets -// let d = dogKeyPathBuilder.master.spouse.pets.color -// XCTAssertEqual(dogKeyPathBuilder.master.spouse.pets.color.keyPathString, "SELF.master.spouse.pets.color") -// -// #endif - let didSetObserver = dog.observe(\.$species, options: [.new, .old]) { (object, change) in XCTAssertEqual(object, dog) diff --git a/CoreStoreTests/WhereTests.swift b/CoreStoreTests/WhereTests.swift index 6dcaed7..a0aa7f0 100644 --- a/CoreStoreTests/WhereTests.swift +++ b/CoreStoreTests/WhereTests.swift @@ -77,17 +77,10 @@ final class WhereTests: XCTestCase { do { -// let keyPathBuilder = TestEntity1.keyPathBuilder() - -// let kp = \TestEntity1.testToOne -// print(keyPathBuilder.testString) -// print(keyPathBuilder.testToOne) -// print(keyPathBuilder.testToOne.testEntityID) XCTAssertAllEqual( #keyPath(TestEntity1.testToOne.testEntityID), (\TestEntity1.testToOne ~ \.testEntityID).description, String(keyPath: \TestEntity1.testToOne ~ \.testEntityID) -// keyPathBuilder.testToOne.testEntityID.keyPathString ) XCTAssertAllEqual( #keyPath(TestEntity1.testToOne.testToOne.testToManyUnordered), diff --git a/Demo/⭐️Sources/⭐️Demos/⭐️Modern/⭐️ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ListView.swift b/Demo/⭐️Sources/⭐️Demos/⭐️Modern/⭐️ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ListView.swift index 55d145c..53c02d4 100644 --- a/Demo/⭐️Sources/⭐️Demos/⭐️Modern/⭐️ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ListView.swift +++ b/Demo/⭐️Sources/⭐️Demos/⭐️Modern/⭐️ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ListView.swift @@ -5,6 +5,7 @@ import CoreStore import SwiftUI + // MARK: - Modern.ColorsDemo.SwiftUI extension Modern.ColorsDemo.SwiftUI { @@ -39,7 +40,7 @@ extension Modern.ColorsDemo.SwiftUI { .listRowInsets(.init()) } .onDelete { itemIndices in - + self.deleteColors(at: itemIndices, in: sectionID) } } diff --git a/Sources/EnvironmentValues+DataSources.swift b/Sources/EnvironmentValues+DataSources.swift index 7f290be..fd6a415 100644 --- a/Sources/EnvironmentValues+DataSources.swift +++ b/Sources/EnvironmentValues+DataSources.swift @@ -45,7 +45,6 @@ extension EnvironmentValues { var dataStack: DataStack ``` */ - @available(*, unavailable, message: "Removed due to being prone to mis-initialization. Please pass your DataStack instance directly, or inject using a method with more deterministic timing.") public var dataStack: DataStack { get { diff --git a/Sources/ObjectPublisher.swift b/Sources/ObjectPublisher.swift index 236914b..9dde96b 100644 --- a/Sources/ObjectPublisher.swift +++ b/Sources/ObjectPublisher.swift @@ -449,20 +449,18 @@ extension ObjectPublisher where O: NSManagedObject { /** Returns the value for the property identified by a given key. */ - @available(*, unavailable, message: "KeyPaths accessed from @dynamicMemberLookup types can't generate KVC keys yet (https://bugs.swift.org/browse/SR-11351)") - public subscript(dynamicMember member: KeyPath) -> V { + public subscript(dynamicMember member: KeyPath) -> V! { - fatalError() -// return self.snapshot[dynamicMember: member] + return self.snapshot?[dynamicMember: member] } - /** - Returns the value for the property identified by a given key. - */ + + // MARK: Deprecated + + @available(*, deprecated, message: "Accessing the property directly now works") public func value(forKeyPath keyPath: KeyPath) -> V! { - let key = String(keyPath: keyPath) - return self.snapshot?.dictionaryForValues()[key] as! V? + return self[dynamicMember: keyPath] } } diff --git a/Sources/ObjectSnapshot.swift b/Sources/ObjectSnapshot.swift index 11902ec..6b8778b 100644 --- a/Sources/ObjectSnapshot.swift +++ b/Sources/ObjectSnapshot.swift @@ -144,29 +144,33 @@ extension ObjectSnapshot where O: NSManagedObject { /** Returns the value for the property identified by a given key. */ - @available(*, unavailable, message: "KeyPaths accessed from @dynamicMemberLookup types can't generate KVC keys yet (https://bugs.swift.org/browse/SR-11351)") - public subscript(dynamicMember member: KeyPath) -> V { + public subscript(dynamicMember member: KeyPath) -> V! { - let key = String(keyPath: member) - return self.values[key] as! V + get { + + let key = String(keyPath: member) + return self.values[key] as! V? + } + set { + + let key = String(keyPath: member) + self.values[key] = newValue + } } - /** - Returns the value for the property identified by a given key. - */ + + // MARK: Deprecated + + @available(*, deprecated, message: "Accessing the property directly now works") public func value(forKeyPath keyPath: KeyPath) -> V! { - let key = String(keyPath: keyPath) - return self.values[key] as! V? + return self[dynamicMember: keyPath] } - /** - Mutates the value for the property identified by a given key. - */ + @available(*, deprecated, message: "Mutating the property directly now works") public mutating func setValue(_ value: V!, forKeyPath keyPath: KeyPath) { - let key = String(keyPath: keyPath) - self.values[key] = value + self[dynamicMember: keyPath] = value } }