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

@@ -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)
}
}