added type-erasers for CoreStoreObject property containers

This commit is contained in:
John Estropia
2017-10-02 12:00:45 +09:00
parent 780ff4e60b
commit 97242d9726
3 changed files with 97 additions and 52 deletions

View File

@@ -520,6 +520,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 /* AnyCoreStoreKeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* AnyCoreStoreKeyPath.swift */; };
B5CA2B131F81DBFE004B1936 /* AnyCoreStoreKeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* AnyCoreStoreKeyPath.swift */; };
B5CA2B141F81DBFE004B1936 /* AnyCoreStoreKeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* AnyCoreStoreKeyPath.swift */; };
B5CA2B151F81DBFF004B1936 /* AnyCoreStoreKeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B111F81DBFE004B1936 /* AnyCoreStoreKeyPath.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 */; };
@@ -862,6 +866,7 @@
B5C976E21C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UnsafeDataTransaction+Observing.swift"; sourceTree = "<group>"; };
B5C976E61C6E3A5900B1AF90 /* CoreStoreFetchedResultsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreFetchedResultsController.swift; sourceTree = "<group>"; };
B5CA2B071F7E5ACA004B1936 /* WhereClauseType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhereClauseType.swift; sourceTree = "<group>"; };
B5CA2B111F81DBFE004B1936 /* AnyCoreStoreKeyPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyCoreStoreKeyPath.swift; sourceTree = "<group>"; };
B5D1E22B19FA9FBC003B2874 /* CoreStoreError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreError.swift; sourceTree = "<group>"; };
B5D339B31E925C2B00C880DE /* DynamicModelTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DynamicModelTests.swift; sourceTree = "<group>"; };
B5D339D71E9489AB00C880DE /* CoreStoreObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreObject.swift; sourceTree = "<group>"; };
@@ -1290,6 +1295,7 @@
children = (
B5A1DAC71F111BFA003CF369 /* KeyPath+Querying.swift */,
B5D339EB1E9495E500C880DE /* CoreStoreObject+Querying.swift */,
B5CA2B111F81DBFE004B1936 /* AnyCoreStoreKeyPath.swift */,
);
name = "KeyPath Utilities";
sourceTree = "<group>";
@@ -1968,6 +1974,7 @@
B549F65E1E569C7400FBAB2D /* QueryableAttributeType.swift in Sources */,
B5E84F211AFF84860064E85B /* CoreStore+Observing.swift in Sources */,
B559CD431CAA8B6300E4D58B /* CSSetupResult.swift in Sources */,
B5CA2B121F81DBFE004B1936 /* AnyCoreStoreKeyPath.swift in Sources */,
B5A991EC1E9DC2CE0091A2E3 /* VersionLock.swift in Sources */,
B5FE4DA71C84FB4400FA6A91 /* InMemoryStore.swift in Sources */,
B52F743D1E9B8724005F3DAC /* DynamicSchema.swift in Sources */,
@@ -2160,6 +2167,7 @@
B549F65F1E569C7400FBAB2D /* QueryableAttributeType.swift in Sources */,
B559CD451CAA8B6300E4D58B /* CSSetupResult.swift in Sources */,
82BA18B81C4BBD4200A0916E /* TypeErasedClauses.swift in Sources */,
B5CA2B131F81DBFE004B1936 /* AnyCoreStoreKeyPath.swift in Sources */,
B5A991ED1E9DC2CE0091A2E3 /* VersionLock.swift in Sources */,
B5ECDBEE1CA6BF2000C7F112 /* CSFrom.swift in Sources */,
B52F743E1E9B8724005F3DAC /* DynamicSchema.swift in Sources */,
@@ -2352,6 +2360,7 @@
B549F6611E569C7400FBAB2D /* QueryableAttributeType.swift in Sources */,
B52DD19B1BE1F92800949AFE /* CoreStoreLogger.swift in Sources */,
B52DD1991BE1F92800949AFE /* DefaultLogger.swift in Sources */,
B5CA2B151F81DBFF004B1936 /* AnyCoreStoreKeyPath.swift in Sources */,
B5A991EF1E9DC2CE0091A2E3 /* VersionLock.swift in Sources */,
B5220E201D130813009BC71E /* CSObjectMonitor.swift in Sources */,
B52F74401E9B8724005F3DAC /* DynamicSchema.swift in Sources */,
@@ -2544,6 +2553,7 @@
B549F6601E569C7400FBAB2D /* QueryableAttributeType.swift in Sources */,
B559CD461CAA8B6300E4D58B /* CSSetupResult.swift in Sources */,
B56321A61BD65216006C9394 /* MigrationType.swift in Sources */,
B5CA2B141F81DBFE004B1936 /* AnyCoreStoreKeyPath.swift in Sources */,
B5A991EE1E9DC2CE0091A2E3 /* VersionLock.swift in Sources */,
B5ECDBEF1CA6BF2000C7F112 /* CSFrom.swift in Sources */,
B52F743F1E9B8724005F3DAC /* DynamicSchema.swift in Sources */,

View File

@@ -0,0 +1,83 @@
//
// AnyCoreStoreKeyPath.swift
// CoreStore
//
// Created by John Estropia on 2017/10/02.
// Copyright © 2017 John Rommel Estropia. All rights reserved.
//
import Foundation
// MARK: - AnyCoreStoreKeyPath
public protocol AnyCoreStoreKeyPath {
var cs_keyPathString: String { get }
}
// SE-0143 is not implemented: https://github.com/apple/swift-evolution/blob/master/proposals/0143-conditional-conformances.md
//extension KeyPath: AnyCoreStoreKeyPath where Root: NSManagedObject, Value: ImportableAttributeType {
//
// public var cs_keyPathString: String {
//
// return self._kvcKeyPathString!
// }
//}
extension ValueContainer.Required: AnyCoreStoreKeyPath {
public var cs_keyPathString: String {
return self.keyPath
}
}
extension ValueContainer.Optional: AnyCoreStoreKeyPath {
public var cs_keyPathString: String {
return self.keyPath
}
}
extension TransformableContainer.Required: AnyCoreStoreKeyPath {
public var cs_keyPathString: String {
return self.keyPath
}
}
extension TransformableContainer.Optional: AnyCoreStoreKeyPath {
public var cs_keyPathString: String {
return self.keyPath
}
}
extension RelationshipContainer.ToOne: AnyCoreStoreKeyPath {
public var cs_keyPathString: String {
return self.keyPath
}
}
extension RelationshipContainer.ToManyOrdered: AnyCoreStoreKeyPath {
public var cs_keyPathString: String {
return self.keyPath
}
}
extension RelationshipContainer.ToManyUnordered: AnyCoreStoreKeyPath {
public var cs_keyPathString: String {
return self.keyPath
}
}

View File

@@ -262,65 +262,17 @@ public extension OrderBy.SortKey where D: CoreStoreObject {
/**
Indicates that the `KeyPathString` should be sorted in ascending order
*/
public static func ascending<DSub, A, T>(_ attribute: (D) -> A) -> OrderBy<D>.SortKey where A: ValueContainer<DSub>.Required<T> {
public static func ascending<T: AnyCoreStoreKeyPath>(_ attribute: (D) -> T) -> OrderBy<D>.SortKey {
return .ascending(attribute(D.meta).keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in ascending order
*/
public static func ascending<DSub, A, T>(_ attribute: (D) -> A) -> OrderBy<D>.SortKey where A: ValueContainer<DSub>.Optional<T> {
return .ascending(attribute(D.meta).keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in ascending order
*/
public static func ascending<DSub, A, T>(_ attribute: (D) -> A) -> OrderBy<D>.SortKey where A: TransformableContainer<DSub>.Required<T> {
return .ascending(attribute(D.meta).keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in ascending order
*/
public static func ascending<DSub, A, T>(_ attribute: (D) -> A) -> OrderBy<D>.SortKey where A: TransformableContainer<DSub>.Optional<T> {
return .ascending(attribute(D.meta).keyPath)
return .ascending(attribute(D.meta).cs_keyPathString)
}
/**
Indicates that the `KeyPathString` should be sorted in descending order
*/
public static func descending<DSub, A, T>(_ attribute: (D) -> A) -> OrderBy<D>.SortKey where A: ValueContainer<DSub>.Required<T> {
public static func descending<T: AnyCoreStoreKeyPath>(_ attribute: (D) -> T) -> OrderBy<D>.SortKey {
return .descending(attribute(D.meta).keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in descending order
*/
public static func descending<DSub, A, T>(_ attribute: (D) -> A) -> OrderBy<D>.SortKey where A: ValueContainer<DSub>.Optional<T> {
return .descending(attribute(D.meta).keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in descending order
*/
public static func descending<DSub, A, T>(_ attribute: (D) -> A) -> OrderBy<D>.SortKey where A: TransformableContainer<DSub>.Required<T> {
return .descending(attribute(D.meta).keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in descending order
*/
public static func descending<DSub, A, T>(_ attribute: (D) -> A) -> OrderBy<D>.SortKey where A: TransformableContainer<DSub>.Optional<T> {
return .descending(attribute(D.meta).keyPath)
return .descending(attribute(D.meta).cs_keyPathString)
}
}