diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index be1d808..c28d06d 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -94,6 +94,8 @@ B51260941E9B28F100402229 /* EntityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260921E9B28F100402229 /* EntityIdentifier.swift */; }; B51260951E9B28F100402229 /* EntityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260921E9B28F100402229 /* EntityIdentifier.swift */; }; B51260961E9B28F100402229 /* EntityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260921E9B28F100402229 /* EntityIdentifier.swift */; }; + B51B5C2B22D43931009FA3BA /* String+KeyPaths.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51B5C2A22D43931009FA3BA /* String+KeyPaths.swift */; }; + B51B5C2D22D43E38009FA3BA /* KeyPath+KeyPaths.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51B5C2C22D43E38009FA3BA /* KeyPath+KeyPaths.swift */; }; B51FE5AB1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */; }; B51FE5AD1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */; }; B51FE5AE1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */; }; @@ -526,10 +528,10 @@ B5CA2B091F7E5ACA004B1936 /* WhereClauseType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B071F7E5ACA004B1936 /* WhereClauseType.swift */; }; B5CA2B0A1F7E5ACA004B1936 /* WhereClauseType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B071F7E5ACA004B1936 /* WhereClauseType.swift */; }; B5CA2B0B1F7E5ACA004B1936 /* WhereClauseType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B071F7E5ACA004B1936 /* WhereClauseType.swift */; }; - B5CA2B121F81DBFE004B1936 /* DynamicKeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* DynamicKeyPath.swift */; }; - B5CA2B131F81DBFE004B1936 /* DynamicKeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* DynamicKeyPath.swift */; }; - B5CA2B141F81DBFE004B1936 /* DynamicKeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* DynamicKeyPath.swift */; }; - B5CA2B151F81DBFF004B1936 /* DynamicKeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* DynamicKeyPath.swift */; }; + B5CA2B121F81DBFE004B1936 /* KeyPathStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* KeyPathStringConvertible.swift */; }; + B5CA2B131F81DBFE004B1936 /* KeyPathStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* KeyPathStringConvertible.swift */; }; + B5CA2B141F81DBFE004B1936 /* KeyPathStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* KeyPathStringConvertible.swift */; }; + B5CA2B151F81DBFF004B1936 /* KeyPathStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* KeyPathStringConvertible.swift */; }; B5D1E22C19FA9FBC003B2874 /* CoreStoreError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5D1E22B19FA9FBC003B2874 /* CoreStoreError.swift */; }; B5D339B41E925C2B00C880DE /* DynamicModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5D339B31E925C2B00C880DE /* DynamicModelTests.swift */; }; B5D339B51E925C2B00C880DE /* DynamicModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5D339B31E925C2B00C880DE /* DynamicModelTests.swift */; }; @@ -770,6 +772,8 @@ B512607E1E97A18000402229 /* CoreStoreObject+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStoreObject+Convenience.swift"; sourceTree = ""; }; B51260881E9B252B00402229 /* NSEntityDescription+DynamicModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSEntityDescription+DynamicModel.swift"; sourceTree = ""; }; B51260921E9B28F100402229 /* EntityIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EntityIdentifier.swift; sourceTree = ""; }; + B51B5C2A22D43931009FA3BA /* String+KeyPaths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+KeyPaths.swift"; sourceTree = ""; }; + B51B5C2C22D43E38009FA3BA /* KeyPath+KeyPaths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyPath+KeyPaths.swift"; sourceTree = ""; }; B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStore+CustomDebugStringConvertible.swift"; sourceTree = ""; }; B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSFetchedResultsController+Convenience.swift"; sourceTree = ""; }; B5215CA31FA47DFD00139E3A /* FetchChainBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchChainBuilder.swift; sourceTree = ""; }; @@ -877,7 +881,7 @@ B5C976E21C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UnsafeDataTransaction+Observing.swift"; sourceTree = ""; }; B5C976E61C6E3A5900B1AF90 /* CoreStoreFetchedResultsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreFetchedResultsController.swift; sourceTree = ""; }; B5CA2B071F7E5ACA004B1936 /* WhereClauseType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhereClauseType.swift; sourceTree = ""; }; - B5CA2B111F81DBFE004B1936 /* DynamicKeyPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicKeyPath.swift; sourceTree = ""; }; + B5CA2B111F81DBFE004B1936 /* KeyPathStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPathStringConvertible.swift; sourceTree = ""; }; B5D1E22B19FA9FBC003B2874 /* CoreStoreError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreError.swift; sourceTree = ""; }; B5D2D5A91F7558CB00A4DE67 /* .cocoapods.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .cocoapods.yml; sourceTree = SOURCE_ROOT; }; B5D339B31E925C2B00C880DE /* DynamicModelTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DynamicModelTests.swift; sourceTree = ""; }; @@ -1165,6 +1169,17 @@ name = Observing; sourceTree = ""; }; + B51B5C2922D43854009FA3BA /* KeyPaths */ = { + isa = PBXGroup; + children = ( + B5CA2B111F81DBFE004B1936 /* KeyPathStringConvertible.swift */, + B5DAFB492203E01D003FCCD0 /* KeyPathGenericBindings.swift */, + B51B5C2C22D43E38009FA3BA /* KeyPath+KeyPaths.swift */, + B51B5C2A22D43931009FA3BA /* String+KeyPaths.swift */, + ); + name = KeyPaths; + sourceTree = ""; + }; B5215CA21FA47BF300139E3A /* Chained Clauses */ = { isa = PBXGroup; children = ( @@ -1323,8 +1338,6 @@ children = ( B5A1DAC71F111BFA003CF369 /* KeyPath+Querying.swift */, B5D339EB1E9495E500C880DE /* CoreStoreObject+Querying.swift */, - B5CA2B111F81DBFE004B1936 /* DynamicKeyPath.swift */, - B5DAFB492203E01D003FCCD0 /* KeyPathGenericBindings.swift */, ); name = "KeyPath Utilities"; sourceTree = ""; @@ -1337,6 +1350,7 @@ B549F6721E56A92800FBAB2D /* CoreDataNativeType.swift */, B5D339F01E94AF5800C880DE /* CoreStoreStrings.swift */, B5E84EDA1AFF84500064E85B /* Setup */, + B51B5C2922D43854009FA3BA /* KeyPaths */, B5E84EE21AFF84610064E85B /* Logging */, B5E84EE91AFF846E0064E85B /* Transactions */, B5E834B61B7630BD001D3D50 /* Importing */, @@ -1902,6 +1916,7 @@ B5C976E31C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift in Sources */, B53FBA121CAB63CB00F0D40A /* Progress+ObjectiveC.swift in Sources */, B5831B751F34AC7A00A9F647 /* RelationshipProtocol.swift in Sources */, + B51B5C2D22D43E38009FA3BA /* KeyPath+KeyPaths.swift in Sources */, B5E1B5A81CAA49E2007FD580 /* CSDataStack+Migrating.swift in Sources */, B5D339F11E94AF5800C880DE /* CoreStoreStrings.swift in Sources */, B56007161B4018AB00A9A8F9 /* MigrationChain.swift in Sources */, @@ -1991,6 +2006,7 @@ B5E84F201AFF84860064E85B /* DataStack+Observing.swift in Sources */, B501FDDD1CA8D05000BE22EF /* CSSectionBy.swift in Sources */, B538BA771D15B3E30003A766 /* CoreStoreBridge.m in Sources */, + B51B5C2B22D43931009FA3BA /* String+KeyPaths.swift in Sources */, B512607F1E97A18000402229 /* CoreStoreObject+Convenience.swift in Sources */, B5E84EF81AFF846E0064E85B /* CoreStore+Transaction.swift in Sources */, B5E84F301AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift in Sources */, @@ -2000,7 +2016,7 @@ B549F65E1E569C7400FBAB2D /* QueryableAttributeType.swift in Sources */, B5E84F211AFF84860064E85B /* CoreStore+Observing.swift in Sources */, B559CD431CAA8B6300E4D58B /* CSSetupResult.swift in Sources */, - B5CA2B121F81DBFE004B1936 /* DynamicKeyPath.swift in Sources */, + B5CA2B121F81DBFE004B1936 /* KeyPathStringConvertible.swift in Sources */, B5A991EC1E9DC2CE0091A2E3 /* VersionLock.swift in Sources */, B5FE4DA71C84FB4400FA6A91 /* InMemoryStore.swift in Sources */, B52F743D1E9B8724005F3DAC /* DynamicSchema.swift in Sources */, @@ -2195,7 +2211,7 @@ B549F65F1E569C7400FBAB2D /* QueryableAttributeType.swift in Sources */, B559CD451CAA8B6300E4D58B /* CSSetupResult.swift in Sources */, 82BA18B81C4BBD4200A0916E /* TypeErasedClauses.swift in Sources */, - B5CA2B131F81DBFE004B1936 /* DynamicKeyPath.swift in Sources */, + B5CA2B131F81DBFE004B1936 /* KeyPathStringConvertible.swift in Sources */, B5A991ED1E9DC2CE0091A2E3 /* VersionLock.swift in Sources */, B5ECDBEE1CA6BF2000C7F112 /* CSFrom.swift in Sources */, B52F743E1E9B8724005F3DAC /* DynamicSchema.swift in Sources */, @@ -2390,7 +2406,7 @@ B549F6611E569C7400FBAB2D /* QueryableAttributeType.swift in Sources */, B52DD19B1BE1F92800949AFE /* CoreStoreLogger.swift in Sources */, B52DD1991BE1F92800949AFE /* DefaultLogger.swift in Sources */, - B5CA2B151F81DBFF004B1936 /* DynamicKeyPath.swift in Sources */, + B5CA2B151F81DBFF004B1936 /* KeyPathStringConvertible.swift in Sources */, B5A991EF1E9DC2CE0091A2E3 /* VersionLock.swift in Sources */, B5220E201D130813009BC71E /* CSObjectMonitor.swift in Sources */, B52F74401E9B8724005F3DAC /* DynamicSchema.swift in Sources */, @@ -2585,7 +2601,7 @@ B549F6601E569C7400FBAB2D /* QueryableAttributeType.swift in Sources */, B559CD461CAA8B6300E4D58B /* CSSetupResult.swift in Sources */, B56321A61BD65216006C9394 /* MigrationType.swift in Sources */, - B5CA2B141F81DBFE004B1936 /* DynamicKeyPath.swift in Sources */, + B5CA2B141F81DBFE004B1936 /* KeyPathStringConvertible.swift in Sources */, B5A991EE1E9DC2CE0091A2E3 /* VersionLock.swift in Sources */, B5ECDBEF1CA6BF2000C7F112 /* CSFrom.swift in Sources */, B52F743F1E9B8724005F3DAC /* DynamicSchema.swift in Sources */, diff --git a/Sources/CoreStoreObject+Querying.swift b/Sources/CoreStoreObject+Querying.swift index c5bb581..dc9d94d 100644 --- a/Sources/CoreStoreObject+Querying.swift +++ b/Sources/CoreStoreObject+Querying.swift @@ -26,7 +26,6 @@ import CoreData import Foundation - // MARK: - ValueContainer.Required extension ValueContainer.Required { diff --git a/Sources/CoreStoreObject.swift b/Sources/CoreStoreObject.swift index eb1dd79..228ee58 100644 --- a/Sources/CoreStoreObject.swift +++ b/Sources/CoreStoreObject.swift @@ -153,9 +153,27 @@ extension DynamicObject where Self: CoreStoreObject { ) return PartialObject(self.rawObject!) } + + + // MARK: Internal internal static var meta: Self { - - return self.init(asMeta: ()) + + let key = ObjectIdentifier(self) + if case let meta as Self = Static.metaCache[key] { + + return meta + } + let meta = self.init(asMeta: ()) + Static.metaCache[key] = meta + return meta } } + + +// MARK: - Static + +fileprivate enum Static { + + fileprivate static var metaCache: [ObjectIdentifier: Any] = [:] +} diff --git a/Sources/DynamicKeyPath.swift b/Sources/DynamicKeyPath.swift deleted file mode 100644 index ef7f365..0000000 --- a/Sources/DynamicKeyPath.swift +++ /dev/null @@ -1,210 +0,0 @@ -// -// DynamicKeyPath.swift -// CoreStore -// -// Copyright © 2018 John Rommel Estropia -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// - -import Foundation -import CoreData - - -// MARK: - AnyDynamicKeyPath - -public protocol AnyDynamicKeyPath { - - /** - The keyPath string - */ - var cs_keyPathString: String { get } -} - - -// MARK: - DynamicKeyPath - -/** - Used only for utility methods. - */ -public protocol DynamicKeyPath: AnyDynamicKeyPath { - - /** - The DynamicObject type - */ - associatedtype ObjectType: DynamicObject - - /** - The Value type - */ - associatedtype ValueType -} - - -// MARK: - KeyPathString - -extension KeyPathString { - - /** - Extracts the keyPath string from the property. - ``` - let keyPath = String(keyPath: \Person.nickname) - ``` - */ - public init(keyPath: KeyPath) { - - self = keyPath.cs_keyPathString - } - - /** - Extracts the keyPath string from the property. - ``` - let keyPath = String(keyPath: \Person.nickname) - ``` - */ - public init(keyPath: KeyPath) { - - self = O.meta[keyPath: keyPath].cs_keyPathString - } - - /** - Extracts the keyPath string from the property. - ``` - let keyPath = String(keyPath: \Person.nickname) - ``` - */ - public init(keyPath: Where.Expression) { - - self = keyPath.cs_keyPathString - } -} - - - -// MARK: - KeyPath: DynamicKeyPath - -extension KeyPath: DynamicKeyPath, AnyDynamicKeyPath where Root: DynamicObject, Value: AllowedObjectiveCKeyPathValue { - - public typealias ObjectType = Root - public typealias ValueType = Value - - public var cs_keyPathString: String { - - return self._kvcKeyPathString! - } -} - - -// MARK: - ValueContainer.Required: DynamicKeyPath - -extension ValueContainer.Required: DynamicKeyPath { - - public typealias ObjectType = O - public typealias ValueType = V - - public var cs_keyPathString: String { - - return self.keyPath - } -} - - -// MARK: - ValueContainer.Optional: DynamicKeyPath - -extension ValueContainer.Optional: DynamicKeyPath { - - public typealias ObjectType = O - public typealias ValueType = V - - public var cs_keyPathString: String { - - return self.keyPath - } -} - - -// MARK: - TransformableContainer.Required: DynamicKeyPath - -extension TransformableContainer.Required: DynamicKeyPath { - - public typealias ObjectType = O - public typealias ValueType = V - - public var cs_keyPathString: String { - - return self.keyPath - } -} - - -// MARK: - TransformableContainer.Optional: DynamicKeyPath - -extension TransformableContainer.Optional: DynamicKeyPath { - - public typealias ObjectType = O - public typealias ValueType = V - - public var cs_keyPathString: String { - - return self.keyPath - } -} - - -// MARK: - RelationshipContainer.ToOne: DynamicKeyPath - -extension RelationshipContainer.ToOne: DynamicKeyPath { - - public typealias ObjectType = O - public typealias ValueType = D - - public var cs_keyPathString: String { - - return self.keyPath - } -} - - -// MARK: - RelationshipContainer.ToManyOrdered: DynamicKeyPath - -extension RelationshipContainer.ToManyOrdered: DynamicKeyPath { - - public typealias ObjectType = O - public typealias ValueType = D - - public var cs_keyPathString: String { - - return self.keyPath - } -} - - -// MARK: - RelationshipContainer.ToManyUnordered: DynamicKeyPath - -extension RelationshipContainer.ToManyUnordered: DynamicKeyPath { - - public typealias ObjectType = O - public typealias ValueType = D - - public var cs_keyPathString: String { - - return self.keyPath - } -} - diff --git a/Sources/Entity.swift b/Sources/Entity.swift index 69d1834..fb77f03 100644 --- a/Sources/Entity.swift +++ b/Sources/Entity.swift @@ -124,7 +124,7 @@ public final class Entity: DynamicEntity { return $0.map { - return (meta[keyPath: $0] as! AnyDynamicKeyPath).cs_keyPathString + return (meta[keyPath: $0] as! AnyKeyPathStringConvertible).cs_keyPathString } } super.init( @@ -156,7 +156,7 @@ public final class Entity: DynamicEntity { return $0.map { - return (meta[keyPath: $0] as! AnyDynamicKeyPath).cs_keyPathString + return (meta[keyPath: $0] as! AnyKeyPathStringConvertible).cs_keyPathString } } super.init( diff --git a/Sources/KeyPath+KeyPaths.swift b/Sources/KeyPath+KeyPaths.swift new file mode 100644 index 0000000..63e9435 --- /dev/null +++ b/Sources/KeyPath+KeyPaths.swift @@ -0,0 +1,46 @@ +// +// KeyPath+KeyPaths.swift +// CoreStore +// +// Copyright © 2019 John Rommel Estropia +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import CoreData +import Foundation + + +// MARK: - KeyPath: AnyKeyPathStringConvertible, KeyPathStringConvertible where Root: NSManagedObject, Value: AllowedObjectiveCKeyPathValue + +extension KeyPath: AnyKeyPathStringConvertible, KeyPathStringConvertible where Root: NSManagedObject, Value: AllowedObjectiveCKeyPathValue { + + // MARK: AnyKeyPathStringConvertible + + public var cs_keyPathString: String { + + return self._kvcKeyPathString! + } + + + // MARK: KeyPathStringConvertible + + public typealias ObjectType = Root + public typealias DestinationValueType = Value +} diff --git a/Sources/KeyPathGenericBindings.swift b/Sources/KeyPathGenericBindings.swift index 72cbb60..29ea924 100644 --- a/Sources/KeyPathGenericBindings.swift +++ b/Sources/KeyPathGenericBindings.swift @@ -92,49 +92,87 @@ extension UUID: AllowedOptionalObjectiveCKeyPathValue {} extension Optional: AllowedObjectiveCKeyPathValue where Wrapped: AllowedOptionalObjectiveCKeyPathValue {} -// MARK: - AllowedObjectiveCCollectionKeyPathValue +// MARK: - AllowedObjectiveCAttributeKeyPathValue /** Used only for utility methods. Types allowed as `Value` generic type to `KeyPath` utilities. */ -public protocol AllowedObjectiveCCollectionKeyPathValue: AllowedOptionalObjectiveCKeyPathValue {} +public protocol AllowedObjectiveCAttributeKeyPathValue: AllowedObjectiveCKeyPathValue {} -extension NSSet: AllowedObjectiveCCollectionKeyPathValue {} +extension Bool: AllowedObjectiveCAttributeKeyPathValue {} -extension NSOrderedSet: AllowedObjectiveCCollectionKeyPathValue {} +extension CGFloat: AllowedObjectiveCAttributeKeyPathValue {} -extension Optional: AllowedObjectiveCCollectionKeyPathValue, AllowedOptionalObjectiveCKeyPathValue where Wrapped: AllowedObjectiveCCollectionKeyPathValue {} +extension Data: AllowedObjectiveCAttributeKeyPathValue {} + +extension Date: AllowedObjectiveCAttributeKeyPathValue {} + +extension Double: AllowedObjectiveCAttributeKeyPathValue {} + +extension Float: AllowedObjectiveCAttributeKeyPathValue {} + +extension Int: AllowedObjectiveCAttributeKeyPathValue {} + +extension Int8: AllowedObjectiveCAttributeKeyPathValue {} + +extension Int16: AllowedObjectiveCAttributeKeyPathValue {} + +extension Int32: AllowedObjectiveCAttributeKeyPathValue {} + +extension Int64: AllowedObjectiveCAttributeKeyPathValue {} + +extension NSData: AllowedObjectiveCAttributeKeyPathValue {} + +extension NSDate: AllowedObjectiveCAttributeKeyPathValue {} + +extension NSNumber: AllowedObjectiveCAttributeKeyPathValue {} + +extension NSString: AllowedObjectiveCAttributeKeyPathValue {} + +extension NSURL: AllowedObjectiveCAttributeKeyPathValue {} + +extension NSUUID: AllowedObjectiveCAttributeKeyPathValue {} + +extension String: AllowedObjectiveCAttributeKeyPathValue {} + +extension URL: AllowedObjectiveCAttributeKeyPathValue {} + +extension UUID: AllowedObjectiveCAttributeKeyPathValue {} + +extension Optional: AllowedObjectiveCAttributeKeyPathValue where Wrapped: AllowedObjectiveCAttributeKeyPathValue, Wrapped: AllowedOptionalObjectiveCKeyPathValue {} -// MARK: - AllowedCoreStoreObjectKeyPathValue +// MARK: - AllowedObjectiveCRelationshipKeyPathValue /** Used only for utility methods. Types allowed as `Value` generic type to `KeyPath` utilities. */ -public protocol AllowedCoreStoreObjectKeyPathValue: DynamicKeyPath {} +public protocol AllowedObjectiveCRelationshipKeyPathValue: AllowedOptionalObjectiveCKeyPathValue {} -extension ValueContainer.Required: AllowedCoreStoreObjectKeyPathValue {} +extension NSManagedObject: AllowedObjectiveCRelationshipKeyPathValue {} -extension ValueContainer.Optional: AllowedCoreStoreObjectKeyPathValue {} +extension NSSet: AllowedObjectiveCRelationshipKeyPathValue {} -extension TransformableContainer.Required: AllowedCoreStoreObjectKeyPathValue {} +extension NSOrderedSet: AllowedObjectiveCRelationshipKeyPathValue {} -extension TransformableContainer.Optional: AllowedCoreStoreObjectKeyPathValue {} - -extension RelationshipContainer.ToOne: AllowedCoreStoreObjectKeyPathValue {} - -extension RelationshipContainer.ToManyOrdered: AllowedCoreStoreObjectKeyPathValue {} - -extension RelationshipContainer.ToManyUnordered: AllowedCoreStoreObjectKeyPathValue {} +extension Optional: AllowedOptionalObjectiveCKeyPathValue, AllowedObjectiveCRelationshipKeyPathValue where Wrapped: AllowedObjectiveCRelationshipKeyPathValue {} -// MARK: - AllowedCoreStoreObjectCollectionKeyPathValue +// MARK: - AllowedObjectiveCToManyRelationshipKeyPathValue /** Used only for utility methods. Types allowed as `Value` generic type to `KeyPath` utilities. */ -public protocol AllowedCoreStoreObjectCollectionKeyPathValue: AllowedCoreStoreObjectKeyPathValue {} +public protocol AllowedObjectiveCToManyRelationshipKeyPathValue: AllowedOptionalObjectiveCKeyPathValue {} -extension RelationshipContainer.ToManyOrdered: AllowedCoreStoreObjectCollectionKeyPathValue {} +extension NSSet: AllowedObjectiveCToManyRelationshipKeyPathValue {} -extension RelationshipContainer.ToManyUnordered: AllowedCoreStoreObjectCollectionKeyPathValue {} +extension NSOrderedSet: AllowedObjectiveCToManyRelationshipKeyPathValue {} + +extension Optional: AllowedObjectiveCToManyRelationshipKeyPathValue where Wrapped: AllowedObjectiveCToManyRelationshipKeyPathValue, Wrapped: AllowedObjectiveCRelationshipKeyPathValue {} + + +// MARK: - Deprecated + +@available(*, deprecated, renamed: "AllowedObjectiveCToManyRelationshipKeyPathValue") +public typealias AllowedCoreStoreObjectCollectionKeyPathValue = AllowedObjectiveCToManyRelationshipKeyPathValue diff --git a/Sources/KeyPathStringConvertible.swift b/Sources/KeyPathStringConvertible.swift new file mode 100644 index 0000000..dfb3fa4 --- /dev/null +++ b/Sources/KeyPathStringConvertible.swift @@ -0,0 +1,103 @@ +// +// KeyPathStringConvertible.swift +// CoreStore +// +// Copyright © 2018 John Rommel Estropia +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation +import CoreData + + +// MARK: - AnyKeyPathStringConvertible + +public protocol AnyKeyPathStringConvertible { + + /** + The keyPath string + */ + var cs_keyPathString: KeyPathString { get } +} + + +// MARK: - KeyPathStringConvertible + +/** + Used only for utility methods. + */ +public protocol KeyPathStringConvertible: AnyKeyPathStringConvertible { + + /** + The DynamicObject type + */ + associatedtype ObjectType: DynamicObject + + /** + The destination value type + */ + associatedtype DestinationValueType +} + + +// MARK: - AttributeKeyPathStringConvertible + +/** + Used only for utility methods. + */ +public protocol AttributeKeyPathStringConvertible: KeyPathStringConvertible { + + /** + The attribute value type + */ + associatedtype ReturnValueType +} + + +// MARK: - RelationshipKeyPathStringConvertible + +/** + Used only for utility methods. + */ +public protocol RelationshipKeyPathStringConvertible: KeyPathStringConvertible { + + /** + The relationship value type + */ + associatedtype ReturnValueType +} + + +// MARK: - ToManyRelationshipKeyPathStringConvertible + +/** + Used only for utility methods. + */ +public protocol ToManyRelationshipKeyPathStringConvertible: RelationshipKeyPathStringConvertible where ReturnValueType: Sequence {} + + +// MARK: - Deprecated + +@available(*, deprecated, renamed: "AnyKeyPathStringConvertible") +public typealias AnyDynamicKeyPath = AnyKeyPathStringConvertible + +@available(*, deprecated, renamed: "KeyPathStringConvertible") +public typealias DynamicKeyPath = KeyPathStringConvertible + diff --git a/Sources/OrderBy.swift b/Sources/OrderBy.swift index cf93ffd..19167d9 100644 --- a/Sources/OrderBy.swift +++ b/Sources/OrderBy.swift @@ -265,7 +265,7 @@ extension OrderBy.SortKey where D: CoreStoreObject { /** Indicates that the `KeyPathString` should be sorted in ascending order */ - public static func ascending(_ attribute: (D) -> K) -> OrderBy.SortKey { + public static func ascending(_ attribute: (D) -> K) -> OrderBy.SortKey { return .ascending(attribute(D.meta).cs_keyPathString) } @@ -273,7 +273,7 @@ extension OrderBy.SortKey where D: CoreStoreObject { /** Indicates that the `KeyPathString` should be sorted in descending order */ - public static func descending(_ attribute: (D) -> K) -> OrderBy.SortKey { + public static func descending(_ attribute: (D) -> K) -> OrderBy.SortKey { return .descending(attribute(D.meta).cs_keyPathString) } diff --git a/Sources/Relationship.swift b/Sources/Relationship.swift index 62fefde..6dfec8a 100644 --- a/Sources/Relationship.swift +++ b/Sources/Relationship.swift @@ -76,7 +76,7 @@ public enum RelationshipContainer { ``` - Important: `Relationship.ToOne` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties. */ - public final class ToOne: RelationshipProtocol { + public final class ToOne: RelationshipKeyPathStringConvertible, RelationshipProtocol { /** Initializes the metadata for the relationship. All relationships require an "inverse", so updates to to this object's relationship are also reflected on its destination object. Make sure to declare this relationship's inverse relationship on its destination object. Due to Swift's compiler limitation, only one of the relationship and its inverse can declare an `inverse:` argument. @@ -215,11 +215,11 @@ public enum RelationshipContainer { affectedByKeyPaths: affectedByKeyPaths() ) } - + /** - The relationship destination object. + The relationship value */ - public var value: D? { + public var value: ReturnValueType { get { @@ -230,6 +230,25 @@ public enum RelationshipContainer { self.nativeValue = newValue?.rawObject } } + + + // MARK: AnyKeyPathStringConvertible + + public var cs_keyPathString: String { + + return self.keyPath + } + + + // MARK: KeyPathStringConvertible + + public typealias ObjectType = O + public typealias DestinationValueType = D + + + // MARK: RelationshipKeyPathStringConvertible + + public typealias ReturnValueType = DestinationValueType? // MARK: RelationshipProtocol @@ -319,7 +338,7 @@ public enum RelationshipContainer { ``` - Important: `Relationship.ToManyOrdered` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties. */ - public final class ToManyOrdered: RelationshipProtocol { + public final class ToManyOrdered: ToManyRelationshipKeyPathStringConvertible, RelationshipProtocol { /** Initializes the metadata for the relationship. All relationships require an "inverse", so updates to to this object's relationship are also reflected on its destination object. Make sure to declare this relationship's inverse relationship on its destination object. Due to Swift's compiler limitation, only one of the relationship and its inverse can declare an `inverse:` argument. @@ -482,11 +501,11 @@ public enum RelationshipContainer { affectedByKeyPaths: affectedByKeyPaths() ) } - + /** - The relationship ordered objects. + The relationship value */ - public var value: [D] { + public var value: ReturnValueType { get { @@ -497,6 +516,25 @@ public enum RelationshipContainer { self.nativeValue = NSOrderedSet(array: newValue.map({ $0.rawObject! })) } } + + + // MARK: AnyKeyPathStringConvertible + + public var cs_keyPathString: String { + + return self.keyPath + } + + + // MARK: KeyPathStringConvertible + + public typealias ObjectType = O + public typealias DestinationValueType = D + + + // MARK: RelationshipKeyPathStringConvertible + + public typealias ReturnValueType = [DestinationValueType] // MARK: RelationshipProtocol @@ -591,7 +629,7 @@ public enum RelationshipContainer { ``` - Important: `Relationship.ToManyUnordered` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties. */ - public final class ToManyUnordered: RelationshipProtocol { + public final class ToManyUnordered: ToManyRelationshipKeyPathStringConvertible, RelationshipProtocol { /** Initializes the metadata for the relationship. All relationships require an "inverse", so updates to to this object's relationship are also reflected on its destination object. Make sure to declare this relationship's inverse relationship on its destination object. Due to Swift's compiler limitation, only one of the relationship and its inverse can declare an `inverse:` argument. @@ -755,11 +793,11 @@ public enum RelationshipContainer { affectedByKeyPaths: affectedByKeyPaths() ) } - + /** - The relationship unordered objects. + The relationship value */ - public var value: Set { + public var value: ReturnValueType { get { @@ -770,6 +808,25 @@ public enum RelationshipContainer { self.nativeValue = NSSet(array: newValue.map({ $0.rawObject! })) } } + + + // MARK: AnyKeyPathStringConvertible + + public var cs_keyPathString: String { + + return self.keyPath + } + + + // MARK: KeyPathStringConvertible + + public typealias ObjectType = O + public typealias DestinationValueType = D + + + // MARK: RelationshipKeyPathStringConvertible + + public typealias ReturnValueType = Set // MARK: RelationshipProtocol diff --git a/Sources/String+KeyPaths.swift b/Sources/String+KeyPaths.swift new file mode 100644 index 0000000..7054891 --- /dev/null +++ b/Sources/String+KeyPaths.swift @@ -0,0 +1,66 @@ +// +// String+KeyPaths.swift +// CoreStore +// +// Copyright © 2019 John Rommel Estropia +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import CoreData +import Foundation + + +// MARK: - KeyPathString + +extension KeyPathString { + + /** + Extracts the keyPath string from the property. + ``` + let keyPath = String(keyPath: \Person.nickname) + ``` + */ + public init(keyPath: KeyPath) { + + self = keyPath.cs_keyPathString + } + + /** + Extracts the keyPath string from the property. + ``` + let keyPath = String(keyPath: \Person.nickname) + ``` + */ + public init(keyPath: KeyPath) { + + self = O.meta[keyPath: keyPath].cs_keyPathString + } + + /** + Extracts the keyPath string from the property. + ``` + let keyPath = String(keyPath: \Person.nickname) + ``` + */ + public init(keyPath: Where.Expression) { + + self = keyPath.cs_keyPathString + } +} diff --git a/Sources/Transformable.swift b/Sources/Transformable.swift index 02ade8d..3f27575 100644 --- a/Sources/Transformable.swift +++ b/Sources/Transformable.swift @@ -73,7 +73,7 @@ public enum TransformableContainer { ``` - Important: `Transformable.Required` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties. */ - public final class Required: AttributeProtocol { + public final class Required: AttributeKeyPathStringConvertible, AttributeProtocol { /** Initializes the metadata for the property. @@ -138,9 +138,9 @@ public enum TransformableContainer { } /** - The property value. + The attribute value */ - public var value: V { + public var value: ReturnValueType { get { @@ -190,6 +190,25 @@ public enum TransformableContainer { } + // MARK: AnyKeyPathStringConvertible + + public var cs_keyPathString: String { + + return self.keyPath + } + + + // MARK: KeyPathStringConvertible + + public typealias ObjectType = O + public typealias DestinationValueType = V + + + // MARK: AttributeKeyPathStringConvertible + + public typealias ReturnValueType = DestinationValueType + + // MARK: AttributeProtocol internal static var attributeType: NSAttributeType { @@ -270,7 +289,7 @@ public enum TransformableContainer { ``` - Important: `Transformable.Optional` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties. */ - public final class Optional: AttributeProtocol { + public final class Optional: AttributeKeyPathStringConvertible, AttributeProtocol { /** Initializes the metadata for the property. @@ -332,9 +351,9 @@ public enum TransformableContainer { } /** - The property value. + The attribute value */ - public var value: V? { + public var value: ReturnValueType { get { @@ -384,6 +403,25 @@ public enum TransformableContainer { } + // MARK: AnyKeyPathStringConvertible + + public var cs_keyPathString: String { + + return self.keyPath + } + + + // MARK: KeyPathStringConvertible + + public typealias ObjectType = O + public typealias DestinationValueType = V + + + // MARK: AttributeKeyPathStringConvertible + + public typealias ReturnValueType = DestinationValueType? + + // MARK: AttributeProtocol internal static var attributeType: NSAttributeType { diff --git a/Sources/Value.swift b/Sources/Value.swift index bd72074..6945299 100644 --- a/Sources/Value.swift +++ b/Sources/Value.swift @@ -73,7 +73,7 @@ public enum ValueContainer { ``` - Important: `Value.Required` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties. */ - public final class Required: AttributeProtocol { + public final class Required: AttributeKeyPathStringConvertible, AttributeProtocol { /** Initializes the metadata for the property. @@ -129,11 +129,11 @@ public enum ValueContainer { self.customSetter = customSetter self.affectedByKeyPaths = affectedByKeyPaths } - + /** - The property value. + The attribute value */ - public var value: V { + public var value: ReturnValueType { get { @@ -183,6 +183,25 @@ public enum ValueContainer { } } } + + + // MARK: AnyKeyPathStringConvertible + + public var cs_keyPathString: String { + + return self.keyPath + } + + + // MARK: KeyPathStringConvertible + + public typealias ObjectType = O + public typealias DestinationValueType = V + + + // MARK: AttributeKeyPathStringConvertible + + public typealias ReturnValueType = DestinationValueType // MARK: AttributeProtocol @@ -265,7 +284,7 @@ public enum ValueContainer { ``` - Important: `Value.Optional` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties. */ - public final class Optional: AttributeProtocol { + public final class Optional: AttributeKeyPathStringConvertible, AttributeProtocol { /** Initializes the metadata for the property. @@ -324,11 +343,11 @@ public enum ValueContainer { self.customSetter = customSetter self.affectedByKeyPaths = affectedByKeyPaths } - + /** - The property value. + The attribute value */ - public var value: V? { + public var value: ReturnValueType { get { @@ -377,6 +396,25 @@ public enum ValueContainer { } } } + + + // MARK: AnyKeyPathStringConvertible + + public var cs_keyPathString: String { + + return self.keyPath + } + + + // MARK: KeyPathStringConvertible + + public typealias ObjectType = O + public typealias DestinationValueType = V + + + // MARK: AttributeKeyPathStringConvertible + + public typealias ReturnValueType = DestinationValueType? // MARK: AttributeProtocol diff --git a/Sources/Where.Expression.swift b/Sources/Where.Expression.swift index bc1808b..73c43b6 100644 --- a/Sources/Where.Expression.swift +++ b/Sources/Where.Expression.swift @@ -30,7 +30,7 @@ import CoreData // MARK: - ~ /** - Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions ``` let owner = CoreStore.fetchOne( From().where( @@ -65,7 +65,7 @@ extension Where { ) ``` */ - public struct Expression: CustomStringConvertible, DynamicKeyPath { + public struct Expression: CustomStringConvertible, KeyPathStringConvertible { /** Currently supports `SingleTarget` and `CollectionTarget`. @@ -73,15 +73,15 @@ extension Where { public typealias Trait = T - // MARK: AnyDynamicKeyPath + // MARK: AnyKeyPathStringConvertible public let cs_keyPathString: String - // MARK: DynamicKeyPath + // MARK: KeyPathStringConvertible public typealias ObjectType = D - public typealias ValueType = V + public typealias DestinationValueType = V // MARK: CustomStringConvertible @@ -128,7 +128,7 @@ extension Where { // MARK: ~ where D: NSManagedObject /** - Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions ``` let owner = CoreStore.fetchOne(From().where((\.master ~ \.name) == "John")) ``` @@ -139,7 +139,7 @@ public func ~().where((\.master ~ \.name) == "John")) ``` @@ -150,29 +150,29 @@ public func ~ ().where((\.master ~ \.pets).count() > 1)) ``` */ -public func ~ (_ lhs: KeyPath, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { +public func ~ (_ lhs: KeyPath, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } /** - Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions ``` let happyPets = CoreStore.fetchAll(From().where((\.master ~ \.pets).count() > 1)) ``` */ -public func ~ (_ lhs: KeyPath, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { +public func ~ (_ lhs: KeyPath, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } /** - Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions ``` let johnsSonInLaw = CoreStore.fetchOne(From().where((\.spouse ~ \.father ~ \.name) == "John")) ``` @@ -183,7 +183,7 @@ public func ~ ().where((\.spouse ~ \.father ~ \.name) == "John")) ``` @@ -194,34 +194,34 @@ public func ~ ().where((\.spouse ~ \.father ~ \.children).count() > 0)) ``` */ -public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } /** - Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions ``` let spouseHasSiblings = CoreStore.fetchOne(From().where((\.spouse ~ \.father ~ \.children).count() > 0)) ``` */ -public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } /** - Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions ``` let spousesWithBadNamingSense = CoreStore.fetchAll(From().where((\.spouse ~ \.pets ~ \.name).any() == "Spot")) ``` */ -public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } @@ -230,12 +230,12 @@ public func ~ ().where((\.master ~ \.name) == "John")) ``` */ -public func ~ (_ lhs: KeyPath.ToOne>, _ rhs: KeyPath) -> Where.Expression.SingleTarget, K.ValueType> where K.ObjectType == O { +public func ~ (_ lhs: KeyPath.ToOne>, _ rhs: KeyPath) -> Where.Expression.SingleTarget, K.DestinationValueType> where K.ObjectType == O { return .init( D.meta[keyPath: lhs].cs_keyPathString, @@ -244,12 +244,12 @@ public func ~ ().where((\.master ~ \.name) == "John")) ``` */ -public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression where K.ObjectType == O { +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression where K.ObjectType == O { return .init( lhs.cs_keyPathString, @@ -258,12 +258,12 @@ public func ~ ().where((\.master ~ \.name) == "John")) ``` */ -public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression where K.ObjectType == O { +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression where K.ObjectType == O { return .init( lhs.cs_keyPathString, @@ -272,12 +272,12 @@ public func ~ ().where((\.master ~ \.pets).count() > 1)) ``` */ -public func ~ (_ lhs: KeyPath.ToOne>, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.ValueType> where K.ObjectType == O { +public func ~ (_ lhs: KeyPath.ToOne>, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.DestinationValueType> where K.ObjectType == O { return .init( D.meta[keyPath: lhs].cs_keyPathString, @@ -286,12 +286,12 @@ public func ~ ().where((\.master ~ \.pets).count() > 1)) ``` */ -public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.ValueType> where K.ObjectType == O { +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.DestinationValueType> where K.ObjectType == O { return .init( lhs.cs_keyPathString, @@ -300,12 +300,12 @@ public func ~ ().where((\.master ~ \.pets).count() > 1)) ``` */ -public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.ValueType> where K.ObjectType == O { +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.DestinationValueType> where K.ObjectType == O { return .init( lhs.cs_keyPathString, @@ -314,12 +314,12 @@ public func ~ ().where((\.master ~ \.pets ~ \.name).any() == "Spot")) ``` */ -public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, KV.ValueType> where KC.ObjectType == D, KV.ObjectType == O { +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, KV.DestinationValueType> where KC.ObjectType == D, KV.ObjectType == O { return .init( lhs.cs_keyPathString, @@ -516,9 +516,9 @@ public func >= (_ lhs: Where.Ex } -// MARK: - KeyPath where Root: NSManagedObject, Value: AllowedObjectiveCCollectionKeyPathValue +// MARK: - KeyPath where Root: NSManagedObject, Value: AllowedObjectiveCToManyRelationshipKeyPathValue -extension KeyPath where Root: NSManagedObject, Value: AllowedObjectiveCCollectionKeyPathValue { +extension KeyPath where Root: NSManagedObject, Value: AllowedObjectiveCToManyRelationshipKeyPathValue { /** Creates a `Where.Expression` clause for COUNT @@ -532,9 +532,9 @@ extension KeyPath where Root: NSManagedObject, Value: AllowedObjectiveCCollectio } } -// MARK: - Where.Expression where D: NSManagedObject, T == Where.CollectionTarget, V: AllowedObjectiveCCollectionKeyPathValue +// MARK: - Where.Expression where D: NSManagedObject, T == Where.CollectionTarget, V: AllowedObjectiveCToManyRelationshipKeyPathValue -extension Where.Expression where D: NSManagedObject, T == Where.CollectionTarget, V: AllowedObjectiveCCollectionKeyPathValue { +extension Where.Expression where D: NSManagedObject, T == Where.CollectionTarget, V: AllowedObjectiveCToManyRelationshipKeyPathValue { /** Creates a `Where.Expression` clause for COUNT @@ -588,9 +588,9 @@ extension Where.Expression where D: NSManagedObject, T == Where.CollectionTar } -// MARK: - KeyPath where Root: CoreStoreObject, Value: AllowedObjectiveCCollectionKeyPathValue +// MARK: - KeyPath where Root: CoreStoreObject, Value: AllowedObjectiveCToManyRelationshipKeyPathValue -extension KeyPath where Root: CoreStoreObject, Value: AllowedCoreStoreObjectCollectionKeyPathValue { +extension KeyPath where Root: CoreStoreObject, Value: ToManyRelationshipKeyPathStringConvertible { /** Creates a `Where.Expression` clause for COUNT