WIP: Query builders

This commit is contained in:
John Rommel Estropia
2017-07-05 08:45:10 +09:00
parent 32743b3aee
commit aff966aac9
25 changed files with 269 additions and 116 deletions

View File

@@ -324,6 +324,10 @@
B5519A601CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; };
B5519A611CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; };
B5519A621CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; };
B55514EA1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.swift */; };
B55514EB1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.swift */; };
B55514EC1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.swift */; };
B55514ED1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.swift */; };
B55717441D15B09E009BDBCA /* CoreStoreBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = B55717421D15AF9C009BDBCA /* CoreStoreBridge.h */; settings = {ATTRIBUTES = (Public, ); }; };
B55717451D15B09F009BDBCA /* CoreStoreBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = B55717421D15AF9C009BDBCA /* CoreStoreBridge.h */; settings = {ATTRIBUTES = (Public, ); }; };
B55717461D15B0A1009BDBCA /* CoreStoreBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = B55717421D15AF9C009BDBCA /* CoreStoreBridge.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -786,6 +790,7 @@
B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSAsynchronousDataTransaction.swift; sourceTree = "<group>"; };
B5548CD51BD65AE00077652A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
B5548CD71BD65AE50077652A /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = DEVELOPER_DIR; };
B55514E91EED8BF900BAB888 /* FetchCondition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchCondition.swift; sourceTree = "<group>"; };
B55717421D15AF9C009BDBCA /* CoreStoreBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreStoreBridge.h; sourceTree = "<group>"; };
B559CD421CAA8B6300E4D58B /* CSSetupResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSetupResult.swift; sourceTree = "<group>"; };
B559CD481CAA8C6D00E4D58B /* CSStorageInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSStorageInterface.swift; sourceTree = "<group>"; };
@@ -1374,6 +1379,7 @@
B5E84F061AFF847B0064E85B /* DataStack+Querying.swift */,
B5E84F071AFF847B0064E85B /* CoreStore+Querying.swift */,
B596BBB51DD5BC67001DCDD9 /* FetchableSource.swift */,
B55514E91EED8BF900BAB888 /* FetchCondition.swift */,
B596BBBA1DD5C39F001DCDD9 /* QueryableSource.swift */,
B549F65D1E569C7400FBAB2D /* QueryableAttributeType.swift */,
B5E84F0A1AFF847B0064E85B /* Protocol Clauses */,
@@ -1794,6 +1800,7 @@
B5D339D81E9489AB00C880DE /* CoreStoreObject.swift in Sources */,
B5D3F6451C887C0A00C7492A /* LegacySQLiteStore.swift in Sources */,
B56923FA1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */,
B55514EA1EED8BF900BAB888 /* FetchCondition.swift in Sources */,
B596BBBB1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */,
B5ECDBFF1CA80CBA00C7F112 /* CSWhere.swift in Sources */,
B5ECDC051CA8138100C7F112 /* CSOrderBy.swift in Sources */,
@@ -1980,6 +1987,7 @@
B5D339D91E9489AB00C880DE /* CoreStoreObject.swift in Sources */,
82BA18CE1C4BBD7100A0916E /* FetchedResultsControllerDelegate.swift in Sources */,
B56923FB1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */,
B55514EB1EED8BF900BAB888 /* FetchCondition.swift in Sources */,
B596BBBC1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */,
B5ECDC011CA80CBA00C7F112 /* CSWhere.swift in Sources */,
B5ECDC071CA8138100C7F112 /* CSOrderBy.swift in Sources */,
@@ -2166,6 +2174,7 @@
B5D339DB1E9489AB00C880DE /* CoreStoreObject.swift in Sources */,
B52DD1951BE1F92500949AFE /* CoreStoreError.swift in Sources */,
B56923FD1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */,
B55514ED1EED8BF900BAB888 /* FetchCondition.swift in Sources */,
B596BBBE1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */,
B546F9601C9A12B800D5AC55 /* CSSQliteStore.swift in Sources */,
B5ECDC0F1CA8161B00C7F112 /* CSGroupBy.swift in Sources */,
@@ -2352,6 +2361,7 @@
B5D339DA1E9489AB00C880DE /* CoreStoreObject.swift in Sources */,
B5ECDC021CA80CBA00C7F112 /* CSWhere.swift in Sources */,
B56923FC1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */,
B55514EC1EED8BF900BAB888 /* FetchCondition.swift in Sources */,
B596BBBD1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */,
B5ECDC081CA8138100C7F112 /* CSOrderBy.swift in Sources */,
B5E1B59B1CAA0C23007FD580 /* CSObjectObserver.swift in Sources */,

View File

@@ -85,7 +85,7 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver {
// MARK: ObjectObserver
func objectMonitor(_ monitor: ObjectMonitor<Palette>, didUpdateObject object: Palette, changedPersistentKeys: Set<RawKeyPath>) {
func objectMonitor(_ monitor: ObjectMonitor<Palette>, didUpdateObject object: Palette, changedPersistentKeys: Set<KeyPathString>) {
self.reloadPaletteInfo(object, changedKeys: changedPersistentKeys)
}

View File

@@ -131,7 +131,7 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Objec
// none
}
func objectMonitor(_ monitor: ObjectMonitor<Place>, didUpdateObject object: Place, changedPersistentKeys: Set<RawKeyPath>) {
func objectMonitor(_ monitor: ObjectMonitor<Place>, didUpdateObject object: Place, changedPersistentKeys: Set<KeyPathString>) {
if let mapView = self.mapView {

View File

@@ -1447,7 +1447,7 @@ class MyViewController: UIViewController, ObjectObserver {
// ...
}
func objectMonitor(monitor: ObjectMonitor<MyPersonEntity>, didUpdateObject object: MyPersonEntity, changedPersistentKeys: Set<RawKeyPath>) {
func objectMonitor(monitor: ObjectMonitor<MyPersonEntity>, didUpdateObject object: MyPersonEntity, changedPersistentKeys: Set<KeyPathString>) {
// ...
}

View File

@@ -41,7 +41,7 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreObjectiveCType {
The list of key path strings to group results with
*/
@objc
public var keyPaths: [RawKeyPath] {
public var keyPaths: [KeyPathString] {
return self.bridgeToSwift.keyPaths
}
@@ -52,7 +52,7 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreObjectiveCType {
- parameter keyPath: a key path string to group results with
*/
@objc
public convenience init(keyPath: RawKeyPath) {
public convenience init(keyPath: KeyPathString) {
self.init(GroupBy(keyPath))
}
@@ -63,7 +63,7 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreObjectiveCType {
- parameter keyPaths: a list of key path strings to group results with
*/
@objc
public convenience init(keyPaths: [RawKeyPath]) {
public convenience init(keyPaths: [KeyPathString]) {
self.init(GroupBy(keyPaths))
}

View File

@@ -45,7 +45,7 @@ public final class CSSectionBy: NSObject, CoreStoreObjectiveCType {
- returns: a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections
*/
@objc
public static func keyPath(_ sectionKeyPath: RawKeyPath) -> CSSectionBy {
public static func keyPath(_ sectionKeyPath: KeyPathString) -> CSSectionBy {
return self.init(SectionBy(sectionKeyPath))
}
@@ -58,7 +58,7 @@ public final class CSSectionBy: NSObject, CoreStoreObjectiveCType {
- returns: a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections
*/
@objc
public static func keyPath(_ sectionKeyPath: RawKeyPath, sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> CSSectionBy {
public static func keyPath(_ sectionKeyPath: KeyPathString, sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> CSSectionBy {
return self.init(SectionBy(sectionKeyPath, sectionIndexTransformer))
}

View File

@@ -48,7 +48,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
- parameter keyPath: the attribute name
*/
@objc
public convenience init(keyPath: RawKeyPath) {
public convenience init(keyPath: KeyPathString) {
self.init(.attribute(keyPath))
}
@@ -65,7 +65,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the average value of an attribute
*/
@objc
public static func average(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> CSSelectTerm {
public static func average(_ keyPath: KeyPathString, as alias: KeyPathString?) -> CSSelectTerm {
return self.init(.average(keyPath, as: alias))
}
@@ -82,7 +82,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
- returns: a `SelectTerm` to a `Select` clause for a count query
*/
@objc
public static func count(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> CSSelectTerm {
public static func count(_ keyPath: KeyPathString, as alias: KeyPathString?) -> CSSelectTerm {
return self.init(.count(keyPath, as: alias))
}
@@ -99,7 +99,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the maximum value for an attribute
*/
@objc
public static func maximum(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> CSSelectTerm {
public static func maximum(_ keyPath: KeyPathString, as alias: KeyPathString?) -> CSSelectTerm {
return self.init(.maximum(keyPath, as: alias))
}
@@ -116,7 +116,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the minimum value for an attribute
*/
@objc
public static func minimum(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> CSSelectTerm {
public static func minimum(_ keyPath: KeyPathString, as alias: KeyPathString?) -> CSSelectTerm {
return self.init(.minimum(keyPath, as: alias))
}
@@ -133,7 +133,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the sum value for an attribute
*/
@objc
public static func sum(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> CSSelectTerm {
public static func sum(_ keyPath: KeyPathString, as alias: KeyPathString?) -> CSSelectTerm {
return self.init(.sum(keyPath, as: alias))
}
@@ -150,7 +150,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
*/
@objc
public static func objectIDAs(_ alias: RawKeyPath? = nil) -> CSSelectTerm {
public static func objectIDAs(_ alias: KeyPathString? = nil) -> CSSelectTerm {
return self.init(.objectID(as: alias))
}

View File

@@ -85,7 +85,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
- parameter value: the arguments for the `==` operator
*/
@objc
public convenience init(keyPath: RawKeyPath, isEqualTo value: CoreDataNativeType?) {
public convenience init(keyPath: KeyPathString, isEqualTo value: CoreDataNativeType?) {
self.init(value == nil || value is NSNull
? Where("\(keyPath) == nil")
@@ -99,7 +99,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
- parameter list: the array to check membership of
*/
@objc
public convenience init(keyPath: RawKeyPath, isMemberOf list: [CoreDataNativeType]) {
public convenience init(keyPath: KeyPathString, isMemberOf list: [CoreDataNativeType]) {
self.init(Where("\(keyPath) IN %@", list as NSArray))
}

View File

@@ -43,7 +43,7 @@
#define CORESTORE_RETURNS_RETAINED __attribute__((ns_returns_retained))
#pragma mark - RawKeyPath Utilities
#pragma mark - KeyPathString Utilities
#define CSKeyPath(type, property) ({ \
type *_je_keypath_dummy __attribute__((unused)); \

View File

@@ -30,5 +30,5 @@ import CoreData
private enum Static {
static let queue = DispatchQueue.concurrent("com.coreStore.coreStoreManagerObjectBarrierQueue")
static var cache: [ObjectIdentifier: [RawKeyPath: Set<RawKeyPath>]] = [:]
static var cache: [ObjectIdentifier: [KeyPathString: Set<KeyPathString>]] = [:]
}

View File

@@ -208,7 +208,7 @@ public final class CoreStoreSchema: DynamicSchema {
}
let rawModel = NSManagedObjectModel()
var entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription] = [:]
var allCustomGettersSetters: [DynamicEntity: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]] = [:]
var allCustomGettersSetters: [DynamicEntity: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter]] = [:]
for entity in self.allEntities {
let (entityDescription, customGetterSetterByKeyPaths) = self.entityDescription(
@@ -253,10 +253,10 @@ public final class CoreStoreSchema: DynamicSchema {
private let allEntities: Set<DynamicEntity>
private var entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription] = [:]
private var customGettersSettersByEntity: [DynamicEntity: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]] = [:]
private var customGettersSettersByEntity: [DynamicEntity: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter]] = [:]
private weak var cachedRawModel: NSManagedObjectModel?
private func entityDescription(for entity: DynamicEntity, initializer: (DynamicEntity, ModelVersion) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter])) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]) {
private func entityDescription(for entity: DynamicEntity, initializer: (DynamicEntity, ModelVersion) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter])) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter]) {
if let cachedEntityDescription = self.entityDescriptionsByEntity[entity] {
@@ -269,7 +269,7 @@ public final class CoreStoreSchema: DynamicSchema {
return (entityDescription, customGetterSetterByKeyPaths)
}
private static func firstPassCreateEntityDescription(from entity: DynamicEntity, in modelVersion: ModelVersion) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]) {
private static func firstPassCreateEntityDescription(from entity: DynamicEntity, in modelVersion: ModelVersion) -> (entity: NSEntityDescription, customGetterSetterByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter]) {
let entityDescription = NSEntityDescription()
entityDescription.coreStoreEntity = entity
@@ -278,8 +278,8 @@ public final class CoreStoreSchema: DynamicSchema {
entityDescription.versionHashModifier = entity.versionHashModifier
entityDescription.managedObjectClassName = CoreStoreManagedObject.cs_subclassName(for: entity, in: modelVersion)
var keyPathsByAffectedKeyPaths: [RawKeyPath: Set<RawKeyPath>] = [:]
var customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter] = [:]
var keyPathsByAffectedKeyPaths: [KeyPathString: Set<KeyPathString>] = [:]
var customGetterSetterByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter] = [:]
func createProperties(for type: CoreStoreObject.Type) -> [NSPropertyDescription] {
var propertyDescriptions: [NSPropertyDescription] = []
@@ -443,9 +443,9 @@ public final class CoreStoreSchema: DynamicSchema {
}
}
private static func fourthPassSynthesizeManagedObjectClasses(for entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription], allCustomGettersSetters: [DynamicEntity: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]]) {
private static func fourthPassSynthesizeManagedObjectClasses(for entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription], allCustomGettersSetters: [DynamicEntity: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter]]) {
func createManagedObjectSubclass(for entityDescription: NSEntityDescription, customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]?) {
func createManagedObjectSubclass(for entityDescription: NSEntityDescription, customGetterSetterByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter]?) {
let superEntity = entityDescription.superentity
let className = entityDescription.managedObjectClassName!

View File

@@ -210,7 +210,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
/**
Accesses the property value via its keyPath.
*/
public subscript(attribute: RawKeyPath) -> Any? {
public subscript(attribute: KeyPathString) -> Any? {
return self.rawObject.cs_accessValueForKVCKey(attribute)
}
@@ -267,7 +267,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
/**
Accesses or mutates the property value via its keyPath.
*/
public subscript(attribute: RawKeyPath) -> Any? {
public subscript(attribute: KeyPathString) -> Any? {
get { return self.rawObject.cs_accessValueForKVCKey(attribute) }
set { self.rawObject.cs_setValue(newValue, forKVCKey: attribute) }
@@ -304,7 +304,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
// MARK: Internal
internal init(_ rawObject: NSManagedObject, _ sourceAttributesByDestinationKey: [RawKeyPath: NSAttributeDescription]) {
internal init(_ rawObject: NSManagedObject, _ sourceAttributesByDestinationKey: [KeyPathString: NSAttributeDescription]) {
self.rawObject = rawObject
self.sourceAttributesByDestinationKey = sourceAttributesByDestinationKey
@@ -314,7 +314,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
// MARK: FilePrivate
fileprivate let rawObject: NSManagedObject
fileprivate let sourceAttributesByDestinationKey: [RawKeyPath: NSAttributeDescription]
fileprivate let sourceAttributesByDestinationKey: [KeyPathString: NSAttributeDescription]
}
@@ -477,7 +477,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
let transformedRenamingIdentifiers = Set(destinationAttributes.keys)
.intersection(sourceAttributes.keys)
var sourceAttributesByDestinationKey: [RawKeyPath: NSAttributeDescription] = [:]
var sourceAttributesByDestinationKey: [KeyPathString: NSAttributeDescription] = [:]
for renamingIdentifier in transformedRenamingIdentifiers {
let sourceAttribute = sourceAttributes[renamingIdentifier]!.attribute
@@ -535,7 +535,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
let userInfo = mapping.userInfo!
let transformer = userInfo[CustomEntityMigrationPolicy.UserInfoKey.transformer]! as! CustomMapping.Transformer
let sourceAttributesByDestinationKey = userInfo[CustomEntityMigrationPolicy.UserInfoKey.sourceAttributesByDestinationKey] as! [RawKeyPath: NSAttributeDescription]
let sourceAttributesByDestinationKey = userInfo[CustomEntityMigrationPolicy.UserInfoKey.sourceAttributesByDestinationKey] as! [KeyPathString: NSAttributeDescription]
var destinationObject: UnsafeDestinationObject?
try transformer(
@@ -585,8 +585,8 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
var insertMappings: Set<CustomMapping> = []
var copyMappings: Set<CustomMapping> = []
var transformMappings: Set<CustomMapping> = []
var allMappedSourceKeys: [RawKeyPath: RawKeyPath] = [:]
var allMappedDestinationKeys: [RawKeyPath: RawKeyPath] = [:]
var allMappedSourceKeys: [KeyPathString: KeyPathString] = [:]
var allMappedDestinationKeys: [KeyPathString: KeyPathString] = [:]
let sourceRenamingIdentifiers = sourceModel.cs_resolvedRenamingIdentities()
let sourceEntityNames = sourceModel.entitiesByName

View File

@@ -0,0 +1,143 @@
//
// FetchCondition.swift
// CoreStore
//
// Copyright © 2017 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
public struct ChainedClauseBuilder<T: DynamicObject> {
public let from: From<T>
public let fetchClauses: [FetchClause] = []
internal init(from: From<T>) {
self.from = from
}
}
extension From: ClauseChain {
public typealias ObjectType = T
public typealias TraitType = FetchTrait
public var builder: ChainedClauseBuilder<T> {
return .init(from: self)
}
}
public struct ChainedWhere<D: DynamicObject, T: ClauseTrait>: ClauseChain {
public typealias ObjectType = D
public typealias TraitType = T
public let builder: ChainedClauseBuilder<ObjectType>
fileprivate init(builder: ChainedClauseBuilder<ObjectType>) {
var newBuilder = builder
// newBuilder.fetchClauses.append(Where())
self.builder = newBuilder
}
}
public struct ChainedOrderBy<D: DynamicObject, T: ClauseTrait>: ClauseChain {
public typealias ObjectType = D
public typealias TraitType = T
public let builder: ChainedClauseBuilder<ObjectType>
fileprivate init(builder: ChainedClauseBuilder<ObjectType>) {
var newBuilder = builder
// newBuilder.fetchClauses.append(Where())
self.builder = newBuilder
}
}
public struct ChainedSelect<D: DynamicObject, T: ClauseTrait>: ClauseChain {
public typealias ObjectType = D
public typealias TraitType = T
public let builder: ChainedClauseBuilder<ObjectType>
fileprivate init(builder: ChainedClauseBuilder<ObjectType>) {
var newBuilder = builder
// newBuilder.fetchClauses.append(Where())
self.builder = newBuilder
}
}
public protocol ClauseTrait {}
public enum FetchTrait: ClauseTrait {}
public enum QueryTrait: ClauseTrait {}
public enum SectionTrait: ClauseTrait {}
public protocol ClauseChain {
associatedtype ObjectType: DynamicObject
associatedtype TraitType: ClauseTrait
var builder: ChainedClauseBuilder<ObjectType> { get }
}
public extension ClauseChain where Self.TraitType == FetchTrait {
public func `where`() -> ChainedWhere<ObjectType, FetchTrait> {
return .init(builder: self.builder)
}
public func orderBy() -> ChainedOrderBy<ObjectType, FetchTrait> {
return .init(builder: self.builder)
}
public func select() -> ChainedSelect<ObjectType, QueryTrait> {
return .init(builder: self.builder)
}
}
public extension ClauseChain where Self.TraitType == QueryTrait {
public func `where`() -> ChainedWhere<ObjectType, QueryTrait> {
return .init(builder: self.builder)
}
public func orderBy() -> ChainedOrderBy<ObjectType, QueryTrait> {
return .init(builder: self.builder)
}
}

View File

@@ -37,7 +37,7 @@ public struct GroupBy: QueryClause, Hashable {
/**
The list of key path strings to group results with
*/
public let keyPaths: [RawKeyPath]
public let keyPaths: [KeyPathString]
/**
Initializes a `GroupBy` clause with an empty list of key path strings
@@ -53,7 +53,7 @@ public struct GroupBy: QueryClause, Hashable {
- parameter keyPath: a key path string to group results with
- parameter keyPaths: a series of key path strings to group results with
*/
public init(_ keyPath: RawKeyPath, _ keyPaths: RawKeyPath...) {
public init(_ keyPath: KeyPathString, _ keyPaths: KeyPathString...) {
self.init([keyPath] + keyPaths)
}
@@ -63,7 +63,7 @@ public struct GroupBy: QueryClause, Hashable {
- parameter keyPaths: a list of key path strings to group results with
*/
public init(_ keyPaths: [RawKeyPath]) {
public init(_ keyPaths: [KeyPathString]) {
self.keyPaths = keyPaths
}

View File

@@ -997,7 +997,7 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
fileprivate var fetchedResultsController: CoreStoreFetchedResultsController
fileprivate let taskGroup = DispatchGroup()
fileprivate let sectionIndexTransformer: (_ sectionName: RawKeyPath?) -> String?
fileprivate let sectionIndexTransformer: (_ sectionName: KeyPathString?) -> String?
private let isSectioned: Bool

View File

@@ -76,14 +76,14 @@ internal extension NSEntityDescription {
}
@nonobjc
internal var keyPathsByAffectedKeyPaths: [RawKeyPath: Set<RawKeyPath>] {
internal var keyPathsByAffectedKeyPaths: [KeyPathString: Set<KeyPathString>] {
get {
if let userInfo = self.userInfo,
let value = userInfo[UserInfoKey.CoreStoreManagedObjectKeyPathsByAffectedKeyPaths] {
return value as! [RawKeyPath: Set<RawKeyPath>]
return value as! [KeyPathString: Set<KeyPathString>]
}
return [:]
}
@@ -97,14 +97,14 @@ internal extension NSEntityDescription {
}
@nonobjc
internal var customGetterSetterByKeyPaths: [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter] {
internal var customGetterSetterByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter] {
get {
if let userInfo = self.userInfo,
let value = userInfo[UserInfoKey.CoreStoreManagedObjectCustomGetterSetterByKeyPaths] {
return value as! [RawKeyPath: CoreStoreManagedObject.CustomGetterSetter]
return value as! [KeyPathString: CoreStoreManagedObject.CustomGetterSetter]
}
return [:]
}

View File

@@ -84,7 +84,7 @@ public extension NSManagedObject {
- returns: the primitive value for the KVC key
*/
@nonobjc @inline(__always)
public func getValue(forKvcKey kvcKey: RawKeyPath) -> Any? {
public func getValue(forKvcKey kvcKey: KeyPathString) -> Any? {
self.willAccessValue(forKey: kvcKey)
defer {
@@ -102,7 +102,7 @@ public extension NSManagedObject {
- returns: the primitive value transformed by the `didGetValue` closure
*/
@nonobjc @inline(__always)
public func getValue<T>(forKvcKey kvcKey: RawKeyPath, didGetValue: (Any?) throws -> T) rethrows -> T {
public func getValue<T>(forKvcKey kvcKey: KeyPathString, didGetValue: (Any?) throws -> T) rethrows -> T {
self.willAccessValue(forKey: kvcKey)
defer {
@@ -121,7 +121,7 @@ public extension NSManagedObject {
- returns: the primitive value transformed by the `didGetValue` closure
*/
@nonobjc @inline(__always)
public func getValue<T>(forKvcKey kvcKey: RawKeyPath, willGetValue: () throws -> Void, didGetValue: (Any?) throws -> T) rethrows -> T {
public func getValue<T>(forKvcKey kvcKey: KeyPathString, willGetValue: () throws -> Void, didGetValue: (Any?) throws -> T) rethrows -> T {
self.willAccessValue(forKey: kvcKey)
defer {
@@ -139,7 +139,7 @@ public extension NSManagedObject {
- parameter KVCKey: the KVC key
*/
@nonobjc @inline(__always)
public func setValue(_ value: Any?, forKvcKey KVCKey: RawKeyPath) {
public func setValue(_ value: Any?, forKvcKey KVCKey: KeyPathString) {
self.willChangeValue(forKey: KVCKey)
defer {
@@ -157,7 +157,7 @@ public extension NSManagedObject {
- parameter didSetValue: called after executing `setPrimitiveValue(forKey:)`.
*/
@nonobjc @inline(__always)
public func setValue(_ value: Any?, forKvcKey KVCKey: RawKeyPath, didSetValue: () -> Void) {
public func setValue(_ value: Any?, forKvcKey KVCKey: KeyPathString, didSetValue: () -> Void) {
self.willChangeValue(forKey: KVCKey)
defer {
@@ -177,7 +177,7 @@ public extension NSManagedObject {
- parameter didSetValue: called after executing `setPrimitiveValue(forKey:)`.
*/
@nonobjc @inline(__always)
public func setValue<T>(_ value: T, forKvcKey KVCKey: RawKeyPath, willSetValue: (T) throws -> Any?, didSetValue: (Any?) -> Void = { _ in }) rethrows {
public func setValue<T>(_ value: T, forKvcKey KVCKey: KeyPathString, willSetValue: (T) throws -> Any?, didSetValue: (Any?) -> Void = { _ in }) rethrows {
self.willChangeValue(forKey: KVCKey)
defer {
@@ -212,7 +212,7 @@ public extension NSManagedObject {
@available(*, deprecated, renamed: "getValue(forKvcKey:)")
@nonobjc
public func accessValueForKVCKey(_ KVCKey: RawKeyPath) -> Any? {
public func accessValueForKVCKey(_ KVCKey: KeyPathString) -> Any? {
self.willAccessValue(forKey: KVCKey)
defer {
@@ -225,7 +225,7 @@ public extension NSManagedObject {
@available(*, deprecated, renamed: "getValue(forKvcKey:didGetValue:)")
@discardableResult
@nonobjc
public func accessValueForKVCKey<T>(_ KVCKey: RawKeyPath, _ didAccessPrimitiveValue: (Any?) throws -> T) rethrows -> T {
public func accessValueForKVCKey<T>(_ KVCKey: KeyPathString, _ didAccessPrimitiveValue: (Any?) throws -> T) rethrows -> T {
self.willAccessValue(forKey: KVCKey)
defer {
@@ -237,7 +237,7 @@ public extension NSManagedObject {
@available(*, deprecated, renamed: "setValue(_:forKvcKey:)")
@nonobjc
public func setValue(_ value: Any?, forKVCKey KVCKey: RawKeyPath) {
public func setValue(_ value: Any?, forKVCKey KVCKey: KeyPathString) {
self.willChangeValue(forKey: KVCKey)
defer {
@@ -250,7 +250,7 @@ public extension NSManagedObject {
@available(*, deprecated, renamed: "setValue(_:forKvcKey:didSetValue:)")
@discardableResult
@nonobjc
public func setValue<T>(_ value: Any?, forKVCKey KVCKey: RawKeyPath, _ didSetPrimitiveValue: (Any?) throws -> T) rethrows -> T {
public func setValue<T>(_ value: Any?, forKVCKey KVCKey: KeyPathString, _ didSetPrimitiveValue: (Any?) throws -> T) rethrows -> T {
self.willChangeValue(forKey: KVCKey)
defer {

View File

@@ -38,7 +38,7 @@ public extension NSManagedObject {
- returns: the primitive value for the KVC key
*/
@objc
public func cs_accessValueForKVCKey(_ KVCKey: RawKeyPath) -> Any? {
public func cs_accessValueForKVCKey(_ KVCKey: KeyPathString) -> Any? {
return self.getValue(forKvcKey: KVCKey)
}
@@ -50,7 +50,7 @@ public extension NSManagedObject {
- parameter KVCKey: the KVC key
*/
@objc
public func cs_setValue(_ value: Any?, forKVCKey KVCKey: RawKeyPath) {
public func cs_setValue(_ value: Any?, forKVCKey KVCKey: KeyPathString) {
self.setValue(value, forKvcKey: KVCKey)
}

View File

@@ -61,7 +61,7 @@ public protocol ObjectObserver: class {
- parameter object: the `DynamicObject` instance being observed
- parameter changedPersistentKeys: a `Set` of key paths for the attributes that were changed. Note that `changedPersistentKeys` only contains keys for attributes/relationships present in the persistent store, thus transient properties will not be reported.
*/
func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didUpdateObject object: ObjectEntityType, changedPersistentKeys: Set<RawKeyPath>)
func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didUpdateObject object: ObjectEntityType, changedPersistentKeys: Set<KeyPathString>)
/**
Handles processing right after `object` is deleted. (Optional)
@@ -81,7 +81,7 @@ public extension ObjectObserver {
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, willUpdateObject object: ObjectEntityType) { }
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didUpdateObject object: ObjectEntityType, changedPersistentKeys: Set<RawKeyPath>) { }
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didUpdateObject object: ObjectEntityType, changedPersistentKeys: Set<KeyPathString>) { }
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didDeleteObject object: ObjectEntityType) { }
}

View File

@@ -27,9 +27,9 @@ import Foundation
import CoreData
// MARK: - RawKeyPath
// MARK: - KeyPathString
public typealias RawKeyPath = String
public typealias KeyPathString = String
// MARK: - SortKey
@@ -40,14 +40,14 @@ public typealias RawKeyPath = String
public enum SortKey {
/**
Indicates that the `RawKeyPath` should be sorted in ascending order
Indicates that the `KeyPathString` should be sorted in ascending order
*/
case ascending(RawKeyPath)
case ascending(KeyPathString)
/**
Indicates that the `RawKeyPath` should be sorted in descending order
Indicates that the `KeyPathString` should be sorted in descending order
*/
case descending(RawKeyPath)
case descending(KeyPathString)
}

View File

@@ -95,7 +95,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
deleteRule: DeleteRule = .nullify,
versionHashModifier: String? = nil,
renamingIdentifier: String? = nil,
@@ -129,7 +129,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>,
deleteRule: DeleteRule = .nullify,
versionHashModifier: String? = nil,
@@ -164,7 +164,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>,
deleteRule: DeleteRule = .nullify,
versionHashModifier: String? = nil,
@@ -199,7 +199,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>,
deleteRule: DeleteRule = .nullify,
versionHashModifier: String? = nil,
@@ -234,14 +234,14 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: RelationshipProtocol
public let keyPath: RawKeyPath
public let keyPath: KeyPathString
internal let isToMany = false
internal let isOrdered = false
internal let deleteRule: NSDeleteRule
internal let minCount: Int = 0
internal let maxCount: Int = 1
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?)
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPathString?)
internal let versionHashModifier: String?
internal let renamingIdentifier: String?
internal let affectedByKeyPaths: () -> Set<String>
@@ -294,7 +294,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: Private
private init(keyPath: RawKeyPath, inverseKeyPath: @escaping () -> RawKeyPath?, deleteRule: DeleteRule, versionHashModifier: String?, renamingIdentifier: String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
private init(keyPath: KeyPathString, inverseKeyPath: @escaping () -> KeyPathString?, deleteRule: DeleteRule, versionHashModifier: String?, renamingIdentifier: String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
self.keyPath = keyPath
self.deleteRule = deleteRule.nativeValue
@@ -341,7 +341,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
minCount: Int = 0,
maxCount: Int = 0,
deleteRule: DeleteRule = .nullify,
@@ -381,7 +381,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
minCount: Int = 0,
maxCount: Int = 0,
inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>,
@@ -422,7 +422,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
minCount: Int = 0,
maxCount: Int = 0,
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>,
@@ -463,7 +463,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
minCount: Int = 0,
maxCount: Int = 0,
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>,
@@ -502,7 +502,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: RelationshipProtocol
public let keyPath: RawKeyPath
public let keyPath: KeyPathString
internal let isToMany = true
internal let isOptional = true
@@ -510,7 +510,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
internal let deleteRule: NSDeleteRule
internal let minCount: Int
internal let maxCount: Int
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?)
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPathString?)
internal let versionHashModifier: String?
internal let renamingIdentifier: String?
internal let affectedByKeyPaths: () -> Set<String>
@@ -615,7 +615,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
deleteRule: DeleteRule = .nullify,
minCount: Int = 0,
maxCount: Int = 0,
@@ -655,7 +655,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>,
deleteRule: DeleteRule = .nullify,
minCount: Int = 0,
@@ -696,7 +696,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>,
deleteRule: DeleteRule = .nullify,
minCount: Int = 0,
@@ -737,7 +737,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>,
deleteRule: DeleteRule = .nullify,
minCount: Int = 0,
@@ -776,7 +776,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: RelationshipProtocol
public let keyPath: RawKeyPath
public let keyPath: KeyPathString
internal let isToMany = true
internal let isOptional = true
@@ -784,7 +784,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
internal let deleteRule: NSDeleteRule
internal let minCount: Int
internal let maxCount: Int
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?)
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPathString?)
internal let versionHashModifier: String?
internal let renamingIdentifier: String?
internal let affectedByKeyPaths: () -> Set<String>
@@ -837,7 +837,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: Private
private init(keyPath: RawKeyPath, inverseKeyPath: @escaping () -> RawKeyPath?, deleteRule: DeleteRule, minCount: Int, maxCount: Int, versionHashModifier: String?, renamingIdentifier: String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
private init(keyPath: KeyPathString, inverseKeyPath: @escaping () -> KeyPathString?, deleteRule: DeleteRule, minCount: Int, maxCount: Int, versionHashModifier: String?, renamingIdentifier: String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
self.keyPath = keyPath
self.deleteRule = deleteRule.nativeValue
@@ -1210,11 +1210,11 @@ extension RelationshipContainer.ToManyUnordered {
internal protocol RelationshipProtocol: class {
var keyPath: RawKeyPath { get }
var keyPath: KeyPathString { get }
var isToMany: Bool { get }
var isOrdered: Bool { get }
var deleteRule: NSDeleteRule { get }
var inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?) { get }
var inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPathString?) { get }
var affectedByKeyPaths: () -> Set<String> { get }
weak var parentObject: CoreStoreObject? { get set }
var versionHashModifier: String? { get }

View File

@@ -47,7 +47,7 @@ public struct SectionBy {
- parameter sectionKeyPath: the key path to use to group the objects into sections
*/
public init(_ sectionKeyPath: RawKeyPath) {
public init(_ sectionKeyPath: KeyPathString) {
self.init(sectionKeyPath, { $0 })
}
@@ -59,7 +59,7 @@ public struct SectionBy {
- parameter sectionKeyPath: the key path to use to group the objects into sections
- parameter sectionIndexTransformer: a closure to transform the value for the key path to an appropriate section name
*/
public init(_ sectionKeyPath: RawKeyPath, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) {
public init(_ sectionKeyPath: KeyPathString, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) {
self.sectionKeyPath = sectionKeyPath
self.sectionIndexTransformer = sectionIndexTransformer
@@ -68,6 +68,6 @@ public struct SectionBy {
// MARK: Internal
internal let sectionKeyPath: RawKeyPath
internal let sectionKeyPath: KeyPathString
internal let sectionIndexTransformer: (_ sectionName: String?) -> String?
}

View File

@@ -74,7 +74,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter keyPath: the attribute name
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
*/
public static func attribute(_ keyPath: RawKeyPath) -> SelectTerm {
public static func attribute(_ keyPath: KeyPathString) -> SelectTerm {
return ._attribute(keyPath)
}
@@ -91,7 +91,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
*/
public static func average(_ keyPath: RawKeyPath, as alias: RawKeyPath? = nil) -> SelectTerm {
public static func average(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm {
return ._aggregate(
function: "average:",
@@ -113,7 +113,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for a count query
*/
public static func count(_ keyPath: RawKeyPath, as alias: RawKeyPath? = nil) -> SelectTerm {
public static func count(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm {
return ._aggregate(
function: "count:",
@@ -135,7 +135,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
*/
public static func maximum(_ keyPath: RawKeyPath, as alias: RawKeyPath? = nil) -> SelectTerm {
public static func maximum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm {
return ._aggregate(
function: "max:",
@@ -157,7 +157,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
*/
public static func minimum(_ keyPath: RawKeyPath, as alias: RawKeyPath? = nil) -> SelectTerm {
public static func minimum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm {
return ._aggregate(
function: "min:",
@@ -179,7 +179,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
*/
public static func sum(_ keyPath: RawKeyPath, as alias: RawKeyPath? = nil) -> SelectTerm {
public static func sum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm {
return ._aggregate(
function: "sum:",
@@ -202,7 +202,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "objecID" is used
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
*/
public static func objectID(as alias: RawKeyPath? = nil) -> SelectTerm {
public static func objectID(as alias: KeyPathString? = nil) -> SelectTerm {
return ._identity(
alias: alias ?? "objectID",
@@ -213,17 +213,17 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
// MARK: ExpressibleByStringLiteral
public init(stringLiteral value: RawKeyPath) {
public init(stringLiteral value: KeyPathString) {
self = ._attribute(value)
}
public init(unicodeScalarLiteral value: RawKeyPath) {
public init(unicodeScalarLiteral value: KeyPathString) {
self = ._attribute(value)
}
public init(extendedGraphemeClusterLiteral value: RawKeyPath) {
public init(extendedGraphemeClusterLiteral value: KeyPathString) {
self = ._attribute(value)
}
@@ -274,8 +274,8 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
// MARK: Internal
case _attribute(RawKeyPath)
case _aggregate(function: String, keyPath: RawKeyPath, alias: String, nativeType: NSAttributeType)
case _attribute(KeyPathString)
case _aggregate(function: String, keyPath: KeyPathString, alias: String, nativeType: NSAttributeType)
case _identity(alias: String, nativeType: NSAttributeType)
}
@@ -479,7 +479,7 @@ internal extension Collection where Iterator.Element == SelectTerm {
fetchRequest.propertiesToFetch = propertiesToFetch
}
internal func keyPathForFirstSelectTerm() -> RawKeyPath {
internal func keyPathForFirstSelectTerm() -> KeyPathString {
switch self.first! {

View File

@@ -124,7 +124,7 @@ public enum ValueContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
`default`: @autoclosure @escaping () -> V,
isIndexed: Bool = false,
isTransient: Bool = false,
@@ -207,7 +207,7 @@ public enum ValueContainer<O: CoreStoreObject> {
return V.cs_rawAttributeType
}
public let keyPath: RawKeyPath
public let keyPath: KeyPathString
internal let isOptional = false
internal let isIndexed: Bool
@@ -323,7 +323,7 @@ public enum ValueContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
`default`: @autoclosure @escaping () -> V? = nil,
isIndexed: Bool = false,
isTransient: Bool = false,
@@ -405,7 +405,7 @@ public enum ValueContainer<O: CoreStoreObject> {
return V.cs_rawAttributeType
}
public let keyPath: RawKeyPath
public let keyPath: KeyPathString
internal let isOptional = true
internal let isIndexed: Bool
internal let isTransient: Bool
@@ -485,7 +485,7 @@ public extension ValueContainer.Required where V: EmptyableAttributeType {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public convenience init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
isIndexed: Bool = false,
isTransient: Bool = false,
versionHashModifier: String? = nil,
@@ -579,7 +579,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
`default`: @autoclosure @escaping () -> V,
isIndexed: Bool = false,
isTransient: Bool = false,
@@ -660,7 +660,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
return .transformableAttributeType
}
public let keyPath: RawKeyPath
public let keyPath: KeyPathString
internal let isOptional = false
internal let isIndexed: Bool
@@ -774,7 +774,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
- parameter affectedByKeyPaths: a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.
*/
public init(
_ keyPath: RawKeyPath,
_ keyPath: KeyPathString,
`default`: @autoclosure @escaping () -> V? = nil,
isIndexed: Bool = false,
isTransient: Bool = false,
@@ -855,7 +855,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
return .transformableAttributeType
}
public let keyPath: RawKeyPath
public let keyPath: KeyPathString
internal let isOptional = true
internal let isIndexed: Bool
@@ -1211,7 +1211,7 @@ internal protocol AttributeProtocol: class {
static var attributeType: NSAttributeType { get }
var keyPath: RawKeyPath { get }
var keyPath: KeyPathString { get }
var isOptional: Bool { get }
var isIndexed: Bool { get }
var isTransient: Bool { get }

View File

@@ -177,7 +177,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
- parameter keyPath: the keyPath to compare with
- parameter value: the arguments for the `==` operator
*/
public init(_ keyPath: RawKeyPath, isEqualTo value: Void?) {
public init(_ keyPath: KeyPathString, isEqualTo value: Void?) {
self.init(NSPredicate(format: "\(keyPath) == nil"))
}
@@ -188,7 +188,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
- parameter keyPath: the keyPath to compare with
- parameter value: the arguments for the `==` operator
*/
public init<T: QueryableAttributeType>(_ keyPath: RawKeyPath, isEqualTo value: T?) {
public init<T: QueryableAttributeType>(_ keyPath: KeyPathString, isEqualTo value: T?) {
switch value {
@@ -207,7 +207,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
- parameter keyPath: the keyPath to compare with
- parameter object: the arguments for the `==` operator
*/
public init<T: DynamicObject>(_ keyPath: RawKeyPath, isEqualTo object: T?) {
public init<T: DynamicObject>(_ keyPath: KeyPathString, isEqualTo object: T?) {
switch object {
@@ -226,7 +226,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
- parameter keyPath: the keyPath to compare with
- parameter list: the sequence to check membership of
*/
public init<S: Sequence>(_ keyPath: RawKeyPath, isMemberOf list: S) where S.Iterator.Element: QueryableAttributeType {
public init<S: Sequence>(_ keyPath: KeyPathString, isMemberOf list: S) where S.Iterator.Element: QueryableAttributeType {
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_toQueryableNativeType() }) as NSArray))
}
@@ -237,7 +237,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
- parameter keyPath: the keyPath to compare with
- parameter list: the sequence to check membership of
*/
public init<S: Sequence>(_ keyPath: RawKeyPath, isMemberOf list: S) where S.Iterator.Element: DynamicObject {
public init<S: Sequence>(_ keyPath: KeyPathString, isMemberOf list: S) where S.Iterator.Element: DynamicObject {
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_id() }) as NSArray))
}