work around issue that crashes the Swift 3.2 compiler (fixes #171)

This commit is contained in:
John Estropia
2017-06-08 20:18:50 +09:00
parent 49b8b9c372
commit f618617053
32 changed files with 280 additions and 622 deletions

View File

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

View File

@@ -49,7 +49,7 @@ class Palette: NSManagedObject {
}
set {
self.setValue(newValue.cs_toImportableNativeType(), forKvcKey: #keyPath(Palette.colorName))
self.setValue(newValue.cs_toQueryableNativeType(), forKvcKey: #keyPath(Palette.colorName))
}
}

View File

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

View File

@@ -36,33 +36,33 @@ class ImportTests: BaseTestDataTestCase {
@objc
dynamic func test_ThatAttributeProtocols_BehaveCorrectly() {
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: true))?.boolValue, true)
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Int16.max))?.int16Value, Int16.max)
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Int32.max))?.int32Value, Int32.max)
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Int64.max))?.int64Value, Int64.max)
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: MAXFLOAT))?.floatValue, MAXFLOAT)
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Double(MAXFLOAT)))?.doubleValue, Double(MAXFLOAT))
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: true))?.boolValue, true)
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: Int16.max))?.int16Value, Int16.max)
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: Int32.max))?.int32Value, Int32.max)
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: Int64.max))?.int64Value, Int64.max)
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: MAXFLOAT))?.floatValue, MAXFLOAT)
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSNumber(value: Double(MAXFLOAT)))?.doubleValue, Double(MAXFLOAT))
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: "1"))?.boolValue, true)
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max)
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max)
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max)
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue)
XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue)
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: "1"))?.boolValue, true)
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max)
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max)
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max)
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue)
XCTAssertEqual(NSDecimalNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue)
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: "1"))?.boolValue, true)
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max)
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max)
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max)
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue)
XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue)
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: "1"))?.boolValue, true)
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max)
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max)
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max)
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue)
XCTAssertEqual(NSNumber.cs_fromQueryableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue)
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: true)))
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Int16.max)))
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Int32.max)))
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Int64.max)))
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: MAXFLOAT)))
XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Double(MAXFLOAT))))
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: true)))
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: Int16.max)))
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: Int32.max)))
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: Int64.max)))
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: MAXFLOAT)))
XCTAssertNil(NSDecimalNumber.cs_fromQueryableNativeType(NSNumber(value: Double(MAXFLOAT))))
XCTAssertEqual(true.cs_toQueryableNativeType(), NSNumber(value: true))
XCTAssertEqual(Int16.max.cs_toQueryableNativeType(), NSNumber(value: Int16.max))

View File

@@ -198,60 +198,58 @@ class ListObserverTests: BaseTestDataTestCase {
return events == 0
}
)
for _ in 1 ... 2 {
let didUpdateObjectExpectation = self.expectation(
forNotification: "listMonitor:didUpdateObject:atIndexPath:",
object: observer,
handler: { (note) -> Bool in
let didUpdateObjectExpectation = self.expectation(
forNotification: "listMonitor:didUpdateObject:atIndexPath:",
object: observer,
handler: { (note) -> Bool in
XCTAssert(events == 1 || events == 2)
let userInfo = note.userInfo
XCTAssertNotNil(userInfo)
XCTAssertEqual(
Set(userInfo?.keys.map({ $0 as! String }) ?? []),
["indexPath", "object"]
)
let indexPath = userInfo?["indexPath"] as? NSIndexPath
let object = userInfo?["object"] as? TestEntity1
switch object?.testEntityID {
XCTAssert(events == 1 || events == 2)
case NSNumber(value: 101)?:
XCTAssertEqual(indexPath?.index(atPosition: 0), 1)
XCTAssertEqual(indexPath?.index(atPosition: 1), 0)
let userInfo = note.userInfo
XCTAssertNotNil(userInfo)
XCTAssertEqual(
Set(userInfo?.keys.map({ $0 as! String }) ?? []),
["indexPath", "object"]
)
XCTAssertEqual(object?.testBoolean, NSNumber(value: true))
XCTAssertEqual(object?.testNumber, NSNumber(value: 11))
XCTAssertEqual(object?.testDecimal, NSDecimalNumber(string: "11"))
XCTAssertEqual(object?.testString, "nil:TestEntity1:11")
XCTAssertEqual(object?.testData, ("nil:TestEntity1:11" as NSString).data(using: String.Encoding.utf8.rawValue)!)
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-11T00:00:00Z")!)
let indexPath = userInfo?["indexPath"] as? NSIndexPath
let object = userInfo?["object"] as? TestEntity1
case NSNumber(value: 102)?:
XCTAssertEqual(indexPath?.index(atPosition: 0), 0)
XCTAssertEqual(indexPath?.index(atPosition: 1), 0)
switch object?.testEntityID {
case NSNumber(value: 101)?:
XCTAssertEqual(indexPath?.index(atPosition: 0), 1)
XCTAssertEqual(indexPath?.index(atPosition: 1), 0)
XCTAssertEqual(object?.testBoolean, NSNumber(value: true))
XCTAssertEqual(object?.testNumber, NSNumber(value: 11))
XCTAssertEqual(object?.testDecimal, NSDecimalNumber(string: "11"))
XCTAssertEqual(object?.testString, "nil:TestEntity1:11")
XCTAssertEqual(object?.testData, ("nil:TestEntity1:11" as NSString).data(using: String.Encoding.utf8.rawValue)!)
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-11T00:00:00Z")!)
case NSNumber(value: 102)?:
XCTAssertEqual(indexPath?.index(atPosition: 0), 0)
XCTAssertEqual(indexPath?.index(atPosition: 1), 0)
XCTAssertEqual(object?.testBoolean, NSNumber(value: false))
XCTAssertEqual(object?.testNumber, NSNumber(value: 22))
XCTAssertEqual(object?.testDecimal, NSDecimalNumber(string: "22"))
XCTAssertEqual(object?.testString, "nil:TestEntity1:22")
XCTAssertEqual(object?.testData, ("nil:TestEntity1:22" as NSString).data(using: String.Encoding.utf8.rawValue)!)
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-22T00:00:00Z")!)
default:
XCTFail()
}
defer {
events += 1
}
return events == 1 || events == 2
XCTAssertEqual(object?.testBoolean, NSNumber(value: false))
XCTAssertEqual(object?.testNumber, NSNumber(value: 22))
XCTAssertEqual(object?.testDecimal, NSDecimalNumber(string: "22"))
XCTAssertEqual(object?.testString, "nil:TestEntity1:22")
XCTAssertEqual(object?.testData, ("nil:TestEntity1:22" as NSString).data(using: String.Encoding.utf8.rawValue)!)
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-22T00:00:00Z")!)
default:
XCTFail()
}
)
}
defer {
events += 1
}
return events == 1 || events == 2
}
)
let didChangeExpectation = self.expectation(
forNotification: "listMonitorDidChange:",
object: observer,
@@ -453,38 +451,35 @@ class ListObserverTests: BaseTestDataTestCase {
return events == 0
}
)
for _ in 1 ... 2 {
let didUpdateObjectExpectation = self.expectation(
forNotification: "listMonitor:didDeleteObject:fromIndexPath:",
object: observer,
handler: { (note) -> Bool in
let didUpdateObjectExpectation = self.expectation(
forNotification: "listMonitor:didDeleteObject:fromIndexPath:",
object: observer,
handler: { (note) -> Bool in
XCTAssert(events == 1 || events == 2)
let userInfo = note.userInfo
XCTAssertNotNil(userInfo)
XCTAssertEqual(
Set(userInfo?.keys.map({ $0 as! String }) ?? []),
["indexPath", "object"]
)
let indexPath = userInfo?["indexPath"] as? NSIndexPath
XCTAssertEqual(indexPath?.section, 0)
XCTAssert(indexPath?.index(atPosition: 1) == 0 || indexPath?.index(atPosition: 1) == 1)
let object = userInfo?["object"] as? TestEntity1
XCTAssertEqual(object?.isDeleted, true)
defer {
XCTAssert(events == 1 || events == 2)
let userInfo = note.userInfo
XCTAssertNotNil(userInfo)
XCTAssertEqual(
Set(userInfo?.keys.map({ $0 as! String }) ?? []),
["indexPath", "object"]
)
let indexPath = userInfo?["indexPath"] as? NSIndexPath
XCTAssertEqual(indexPath?.section, 0)
XCTAssert(indexPath?.index(atPosition: 1) == 0 || indexPath?.index(atPosition: 1) == 1)
let object = userInfo?["object"] as? TestEntity1
XCTAssertEqual(object?.isDeleted, true)
defer {
events += 1
}
return events == 1 || events == 2
events += 1
}
)
}
return events == 1 || events == 2
}
)
let didDeleteSectionExpectation = self.expectation(
forNotification: "listMonitor:didDeleteSection:fromSectionIndex:",
object: observer,
@@ -531,10 +526,11 @@ class ListObserverTests: BaseTestDataTestCase {
stack.perform(
asynchronous: { (transaction) -> Bool in
transaction.deleteAll(
let count = transaction.deleteAll(
From<TestEntity1>(),
Where(#keyPath(TestEntity1.testBoolean), isEqualTo: false)
)
XCTAssertEqual(count, 2)
return transaction.hasChanges
},
success: { (hasChanges) in

View File

@@ -219,7 +219,7 @@ class TestObjectObserver: ObjectObserver {
)
}
func objectMonitor(_ monitor: ObjectMonitor<TestEntity1>, didUpdateObject object: TestEntity1, changedPersistentKeys: Set<KeyPath>) {
func objectMonitor(_ monitor: ObjectMonitor<TestEntity1>, didUpdateObject object: TestEntity1, changedPersistentKeys: Set<String>) {
NotificationCenter.default.post(
name: NSNotification.Name(rawValue: "objectMonitor:didUpdateObject:changedPersistentKeys:"),

View File

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

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: [KeyPath] {
public var keyPaths: [RawKeyPath] {
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: KeyPath) {
public convenience init(keyPath: RawKeyPath) {
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: [KeyPath]) {
public convenience init(keyPaths: [RawKeyPath]) {
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: KeyPath) -> CSSectionBy {
public static func keyPath(_ sectionKeyPath: RawKeyPath) -> 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: KeyPath, sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> CSSectionBy {
public static func keyPath(_ sectionKeyPath: RawKeyPath, 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: KeyPath) {
public convenience init(keyPath: RawKeyPath) {
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: KeyPath, as alias: KeyPath?) -> CSSelectTerm {
public static func average(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> 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: KeyPath, as alias: KeyPath?) -> CSSelectTerm {
public static func count(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> 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: KeyPath, as alias: KeyPath?) -> CSSelectTerm {
public static func maximum(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> 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: KeyPath, as alias: KeyPath?) -> CSSelectTerm {
public static func minimum(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> 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: KeyPath, as alias: KeyPath?) -> CSSelectTerm {
public static func sum(_ keyPath: RawKeyPath, as alias: RawKeyPath?) -> 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: KeyPath? = nil) -> CSSelectTerm {
public static func objectIDAs(_ alias: RawKeyPath? = 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: KeyPath, isEqualTo value: CoreDataNativeType?) {
public convenience init(keyPath: RawKeyPath, 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: KeyPath, isMemberOf list: [CoreDataNativeType]) {
public convenience init(keyPath: RawKeyPath, 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 - KeyPath Utilities
#pragma mark - RawKeyPath Utilities
#define CSKeyPath(type, property) ({ \
type *_je_keypath_dummy __attribute__((unused)); \

View File

@@ -14,7 +14,7 @@ import CoreData
@objc internal class CoreStoreManagedObject: NSManagedObject {
@nonobjc
internal class func cs_setKeyPathsForValuesAffectingKeys(_ keyPathsForValuesAffectingKeys: [KeyPath: Set<KeyPath>], for managedObjectClass: CoreStoreManagedObject.Type) {
internal class func cs_setKeyPathsForValuesAffectingKeys(_ keyPathsForValuesAffectingKeys: [RawKeyPath: Set<RawKeyPath>], for managedObjectClass: CoreStoreManagedObject.Type) {
Static.queue.sync(flags: .barrier) {
@@ -44,5 +44,5 @@ import CoreData
private enum Static {
static let queue = DispatchQueue.concurrent("com.coreStore.coreStoreManagerObjectBarrierQueue")
static var cache: [ObjectIdentifier: [KeyPath: Set<KeyPath>]] = [:]
static var cache: [ObjectIdentifier: [RawKeyPath: Set<RawKeyPath>]] = [:]
}

View File

@@ -270,7 +270,7 @@ public final class CoreStoreSchema: DynamicSchema {
entityDescription.versionHashModifier = entity.versionHashModifier
entityDescription.managedObjectClassName = "\(NSStringFromClass(CoreStoreManagedObject.self)).\(NSStringFromClass(entity.type)).\(entity.entityName)"
var keyPathsByAffectedKeyPaths: [KeyPath: Set<KeyPath>] = [:]
var keyPathsByAffectedKeyPaths: [RawKeyPath: Set<RawKeyPath>] = [:]
func createProperties(for type: CoreStoreObject.Type) -> [NSPropertyDescription] {
var propertyDescriptions: [NSPropertyDescription] = []

View File

@@ -210,7 +210,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
/**
Accesses the property value via its keyPath.
*/
public subscript(attribute: KeyPath) -> Any? {
public subscript(attribute: RawKeyPath) -> 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: KeyPath) -> Any? {
public subscript(attribute: RawKeyPath) -> 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: [KeyPath: NSAttributeDescription]) {
internal init(_ rawObject: NSManagedObject, _ sourceAttributesByDestinationKey: [RawKeyPath: 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: [KeyPath: NSAttributeDescription]
fileprivate let sourceAttributesByDestinationKey: [RawKeyPath: NSAttributeDescription]
}
@@ -477,7 +477,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
let transformedRenamingIdentifiers = Set(destinationAttributes.keys)
.intersection(sourceAttributes.keys)
var sourceAttributesByDestinationKey: [KeyPath: NSAttributeDescription] = [:]
var sourceAttributesByDestinationKey: [RawKeyPath: 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! [KeyPath: NSAttributeDescription]
let sourceAttributesByDestinationKey = userInfo[CustomEntityMigrationPolicy.UserInfoKey.sourceAttributesByDestinationKey] as! [RawKeyPath: 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: [KeyPath: KeyPath] = [:]
var allMappedDestinationKeys: [KeyPath: KeyPath] = [:]
var allMappedSourceKeys: [RawKeyPath: RawKeyPath] = [:]
var allMappedDestinationKeys: [RawKeyPath: RawKeyPath] = [:]
let sourceRenamingIdentifiers = sourceModel.cs_resolvedRenamingIdentities()
let sourceEntityNames = sourceModel.entitiesByName

View File

@@ -61,10 +61,6 @@ public extension DataStack {
)
transaction.transactionQueue.cs_async {
defer {
withExtendedLifetime((self, transaction), {})
}
let userInfo: T
do {
@@ -82,6 +78,10 @@ public extension DataStack {
}
transaction.autoCommit { (_, error) in
defer {
withExtendedLifetime((self, transaction), {})
}
if let error = error {
failure(error)

View File

@@ -96,49 +96,49 @@ public extension DynamicSchema {
case .integer16AttributeType:
valueType = Int16.self
if let defaultValue = (attribute.defaultValue as! Int16.ImportableNativeType?).flatMap(Int16.cs_fromImportableNativeType),
if let defaultValue = (attribute.defaultValue as! Int16.QueryableNativeType?).flatMap(Int16.cs_fromQueryableNativeType),
defaultValue != Int16.cs_emptyValue() {
defaultString = ", default: \(defaultValue)"
}
case .integer32AttributeType:
valueType = Int32.self
if let defaultValue = (attribute.defaultValue as! Int32.ImportableNativeType?).flatMap(Int32.cs_fromImportableNativeType),
if let defaultValue = (attribute.defaultValue as! Int32.QueryableNativeType?).flatMap(Int32.cs_fromQueryableNativeType),
defaultValue != Int32.cs_emptyValue() {
defaultString = ", default: \(defaultValue)"
}
case .integer64AttributeType:
valueType = Int64.self
if let defaultValue = (attribute.defaultValue as! Int64.ImportableNativeType?).flatMap(Int64.cs_fromImportableNativeType),
if let defaultValue = (attribute.defaultValue as! Int64.QueryableNativeType?).flatMap(Int64.cs_fromQueryableNativeType),
defaultValue != Int64.cs_emptyValue() {
defaultString = ", default: \(defaultValue)"
}
case .decimalAttributeType:
valueType = NSDecimalNumber.self
if let defaultValue = (attribute.defaultValue as! NSDecimalNumber.ImportableNativeType?).flatMap(NSDecimalNumber.cs_fromImportableNativeType),
if let defaultValue = (attribute.defaultValue as! NSDecimalNumber.QueryableNativeType?).flatMap(NSDecimalNumber.cs_fromQueryableNativeType),
defaultValue != NSDecimalNumber.cs_emptyValue() {
defaultString = ", default: NSDecimalNumber(string: \"\(defaultValue.description(withLocale: nil))\")"
}
case .doubleAttributeType:
valueType = Double.self
if let defaultValue = (attribute.defaultValue as! Double.ImportableNativeType?).flatMap(Double.cs_fromImportableNativeType),
if let defaultValue = (attribute.defaultValue as! Double.QueryableNativeType?).flatMap(Double.cs_fromQueryableNativeType),
defaultValue != Double.cs_emptyValue() {
defaultString = ", default: \(defaultValue)"
}
case .floatAttributeType:
valueType = Float.self
if let defaultValue = (attribute.defaultValue as! Float.ImportableNativeType?).flatMap(Float.cs_fromImportableNativeType),
if let defaultValue = (attribute.defaultValue as! Float.QueryableNativeType?).flatMap(Float.cs_fromQueryableNativeType),
defaultValue != Float.cs_emptyValue() {
defaultString = ", default: \(defaultValue)"
}
case .stringAttributeType:
valueType = String.self
if let defaultValue = (attribute.defaultValue as! String.ImportableNativeType?).flatMap(String.cs_fromImportableNativeType),
if let defaultValue = (attribute.defaultValue as! String.QueryableNativeType?).flatMap(String.cs_fromQueryableNativeType),
defaultValue != String.cs_emptyValue() {
// TODO: escape strings
@@ -146,20 +146,20 @@ public extension DynamicSchema {
}
case .booleanAttributeType:
valueType = Bool.self
if let defaultValue = (attribute.defaultValue as! Bool.ImportableNativeType?).flatMap(Bool.cs_fromImportableNativeType),
if let defaultValue = (attribute.defaultValue as! Bool.QueryableNativeType?).flatMap(Bool.cs_fromQueryableNativeType),
defaultValue != Bool.cs_emptyValue() {
defaultString = ", default: \(defaultValue ? "true" : "false")"
}
case .dateAttributeType:
valueType = Date.self
if let defaultValue = (attribute.defaultValue as! Date.ImportableNativeType?).flatMap(Date.cs_fromImportableNativeType) {
if let defaultValue = (attribute.defaultValue as! Date.QueryableNativeType?).flatMap(Date.cs_fromQueryableNativeType) {
defaultString = ", default: Date(timeIntervalSinceReferenceDate: \(defaultValue.timeIntervalSinceReferenceDate))"
}
case .binaryDataAttributeType:
valueType = Data.self
if let defaultValue = (attribute.defaultValue as! Data.ImportableNativeType?).flatMap(Data.cs_fromImportableNativeType),
if let defaultValue = (attribute.defaultValue as! Data.QueryableNativeType?).flatMap(Data.cs_fromQueryableNativeType),
defaultValue != Data.cs_emptyValue() {
let count = defaultValue.count

View File

@@ -37,7 +37,7 @@ public struct GroupBy: QueryClause, Hashable {
/**
The list of key path strings to group results with
*/
public let keyPaths: [KeyPath]
public let keyPaths: [RawKeyPath]
/**
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: KeyPath, _ keyPaths: KeyPath...) {
public init(_ keyPath: RawKeyPath, _ keyPaths: RawKeyPath...) {
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: [KeyPath]) {
public init(_ keyPaths: [RawKeyPath]) {
self.keyPaths = keyPaths
}

View File

@@ -57,25 +57,7 @@ import CoreGraphics
In addition, `RawRepresentable` types whose `RawValue` already implements `ImportableAttributeType` only need to declare conformance to `ImportableAttributeType`.
*/
public protocol ImportableAttributeType: QueryableAttributeType {
/**
The `CoreDataNativeType` for this type.
*/
associatedtype ImportableNativeType: QueryableNativeType
/**
Creates an instance of this type from its `ImportableNativeType` value.
*/
@inline(__always)
static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self?
/**
Creates `ImportableNativeType` value from this instance.
*/
@inline(__always)
func cs_toImportableNativeType() -> ImportableNativeType
}
public protocol ImportableAttributeType: QueryableAttributeType {}
// MARK: - EmptyableAttributeType
@@ -99,22 +81,6 @@ public protocol EmptyableAttributeType: ImportableAttributeType {
extension Bool: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSNumber
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Bool? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@@ -130,23 +96,6 @@ extension Bool: ImportableAttributeType, EmptyableAttributeType {
extension CGFloat: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSNumber
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> CGFloat? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@inline(__always)
@@ -161,23 +110,6 @@ extension CGFloat: ImportableAttributeType, EmptyableAttributeType {
extension Data: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSData
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Data? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@inline(__always)
@@ -190,47 +122,13 @@ extension Data: ImportableAttributeType, EmptyableAttributeType {
// MARK: - Date
extension Date: ImportableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSDate
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Date? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
}
extension Date: ImportableAttributeType {}
// MARK: - Double
extension Double: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSNumber
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Double? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@inline(__always)
@@ -245,23 +143,6 @@ extension Double: ImportableAttributeType, EmptyableAttributeType {
extension Float: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSNumber
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Float? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@inline(__always)
@@ -276,23 +157,6 @@ extension Float: ImportableAttributeType, EmptyableAttributeType {
extension Int: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSNumber
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@inline(__always)
@@ -307,23 +171,6 @@ extension Int: ImportableAttributeType, EmptyableAttributeType {
extension Int8: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSNumber
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int8? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@inline(__always)
@@ -338,23 +185,6 @@ extension Int8: ImportableAttributeType, EmptyableAttributeType {
extension Int16: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSNumber
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int16? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@inline(__always)
@@ -369,23 +199,6 @@ extension Int16: ImportableAttributeType, EmptyableAttributeType {
extension Int32: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSNumber
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int32? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@inline(__always)
@@ -400,23 +213,6 @@ extension Int32: ImportableAttributeType, EmptyableAttributeType {
extension Int64: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSNumber
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int64? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@inline(__always)
@@ -431,23 +227,6 @@ extension Int64: ImportableAttributeType, EmptyableAttributeType {
extension NSData: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSData
@nonobjc @inline(__always)
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
return self.cs_fromQueryableNativeType(value)
}
@nonobjc @inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@nonobjc @inline(__always)
@@ -460,47 +239,13 @@ extension NSData: ImportableAttributeType, EmptyableAttributeType {
// MARK: - NSDate
extension NSDate: ImportableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSDate
@nonobjc @inline(__always)
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
return self.cs_fromQueryableNativeType(value)
}
@nonobjc @inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
}
extension NSDate: ImportableAttributeType {}
// MARK: - NSNumber
extension NSNumber: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSNumber
@nonobjc @inline(__always)
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
return self.cs_fromQueryableNativeType(value)
}
@nonobjc @inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@nonobjc @inline(__always)
@@ -515,23 +260,6 @@ extension NSNumber: ImportableAttributeType, EmptyableAttributeType {
extension NSString: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSString
@nonobjc @inline(__always)
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
return self.cs_fromQueryableNativeType(value)
}
@nonobjc @inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@nonobjc @inline(__always)
@@ -544,69 +272,18 @@ extension NSString: ImportableAttributeType, EmptyableAttributeType {
// MARK: - NSURL
extension NSURL: ImportableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSString
@nonobjc @inline(__always)
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
return self.cs_fromQueryableNativeType(value)
}
@nonobjc @inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
}
extension NSURL: ImportableAttributeType {}
// MARK: - NSUUID
extension NSUUID: ImportableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSString
@nonobjc @inline(__always)
public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
return self.cs_fromQueryableNativeType(value)
}
@nonobjc @inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
}
extension NSUUID: ImportableAttributeType {}
// MARK: - String
extension String: ImportableAttributeType, EmptyableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSString
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> String? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
// MARK: EmptyableAttributeType
@inline(__always)
@@ -619,63 +296,27 @@ extension String: ImportableAttributeType, EmptyableAttributeType {
// MARK: - URL
extension URL: ImportableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSString
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> URL? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
}
extension URL: ImportableAttributeType {}
// MARK: - UUID
extension UUID: ImportableAttributeType {
// MARK: ImportableAttributeType
public typealias ImportableNativeType = NSString
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> UUID? {
return self.cs_fromQueryableNativeType(value)
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
return self.cs_toQueryableNativeType()
}
}
extension UUID: ImportableAttributeType {}
// MARK: - RawRepresentable
extension RawRepresentable where RawValue: ImportableAttributeType {
public typealias ImportableNativeType = RawValue.ImportableNativeType
@inline(__always)
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? {
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
return RawValue.cs_fromImportableNativeType(value).flatMap({ self.init(rawValue: $0) })
return RawValue.cs_fromQueryableNativeType(value).flatMap({ self.init(rawValue: $0) })
}
@inline(__always)
public func cs_toImportableNativeType() -> ImportableNativeType {
public func cs_toQueryableNativeType() -> QueryableNativeType {
return self.rawValue.cs_toImportableNativeType()
return self.rawValue.cs_toQueryableNativeType()
}
}

View File

@@ -118,7 +118,7 @@ public protocol ImportableUniqueObject: ImportableObject {
// MARK: - ImportableUniqueObject (Default Implementations)
public extension ImportableUniqueObject {
public extension ImportableUniqueObject where UniqueIDType.QueryableNativeType: CoreDataNativeType {
var uniqueIDValue: UniqueIDType {
@@ -126,7 +126,7 @@ public extension ImportableUniqueObject {
return self.cs_toRaw().getValue(
forKvcKey: type(of: self).uniqueIDKeyPath,
didGetValue: { UniqueIDType.cs_fromImportableNativeType($0 as! UniqueIDType.ImportableNativeType)! }
didGetValue: { UniqueIDType.cs_fromQueryableNativeType($0 as! UniqueIDType.QueryableNativeType)! }
)
}
set {
@@ -135,10 +135,13 @@ public extension ImportableUniqueObject {
.setValue(
newValue,
forKvcKey: type(of: self).uniqueIDKeyPath,
willSetValue: { ($0.cs_toImportableNativeType() as! CoreDataNativeType) }
)
willSetValue: { ($0.cs_toQueryableNativeType() as CoreDataNativeType) }
)
}
}
}
public extension ImportableUniqueObject {
static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool {

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: KeyPath?) -> String?
fileprivate let sectionIndexTransformer: (_ sectionName: RawKeyPath?) -> String?
private let isSectioned: Bool

View File

@@ -75,12 +75,12 @@ internal extension NSEntityDescription {
}
}
internal var keyPathsByAffectedKeyPaths: [KeyPath: Set<KeyPath>] {
internal var keyPathsByAffectedKeyPaths: [RawKeyPath: Set<RawKeyPath>] {
get {
if let userInfo = self.userInfo,
let function = userInfo[UserInfoKey.CoreStoreManagedObjectKeyPathsByAffectedKeyPaths] as! [KeyPath: Set<KeyPath>]? {
let function = userInfo[UserInfoKey.CoreStoreManagedObjectKeyPathsByAffectedKeyPaths] as! [RawKeyPath: Set<RawKeyPath>]? {
return function
}

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: KeyPath) -> Any? {
public func getValue(forKvcKey kvcKey: RawKeyPath) -> 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: KeyPath, didGetValue: (Any?) throws -> T) rethrows -> T {
public func getValue<T>(forKvcKey kvcKey: RawKeyPath, 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: KeyPath, willGetValue: () throws -> Void, didGetValue: (Any?) throws -> T) rethrows -> T {
public func getValue<T>(forKvcKey kvcKey: RawKeyPath, 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: KeyPath) {
public func setValue(_ value: Any?, forKvcKey KVCKey: RawKeyPath) {
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: KeyPath, didSetValue: () -> Void) {
public func setValue(_ value: Any?, forKvcKey KVCKey: RawKeyPath, 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: KeyPath, willSetValue: (T) throws -> Any?, didSetValue: (Any?) -> Void = { _ in }) rethrows {
public func setValue<T>(_ value: T, forKvcKey KVCKey: RawKeyPath, 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: KeyPath) -> Any? {
public func accessValueForKVCKey(_ KVCKey: RawKeyPath) -> 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: KeyPath, _ didAccessPrimitiveValue: (Any?) throws -> T) rethrows -> T {
public func accessValueForKVCKey<T>(_ KVCKey: RawKeyPath, _ 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: KeyPath) {
public func setValue(_ value: Any?, forKVCKey KVCKey: RawKeyPath) {
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: KeyPath, _ didSetPrimitiveValue: (Any?) throws -> T) rethrows -> T {
public func setValue<T>(_ value: Any?, forKVCKey KVCKey: RawKeyPath, _ 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: KeyPath) -> Any? {
public func cs_accessValueForKVCKey(_ KVCKey: RawKeyPath) -> 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: KeyPath) {
public func cs_setValue(_ value: Any?, forKVCKey KVCKey: RawKeyPath) {
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<KeyPath>)
func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didUpdateObject object: ObjectEntityType, changedPersistentKeys: Set<RawKeyPath>)
/**
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<KeyPath>) { }
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didUpdateObject object: ObjectEntityType, changedPersistentKeys: Set<RawKeyPath>) { }
public func objectMonitor(_ monitor: ObjectMonitor<ObjectEntityType>, didDeleteObject object: ObjectEntityType) { }
}

View File

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

View File

@@ -64,7 +64,7 @@ public protocol QueryableAttributeType: Hashable, SelectResultType {
/**
The `CoreDataNativeType` for this type when used in `Select` clauses.
*/
associatedtype QueryableNativeType: CoreDataNativeType
associatedtype QueryableNativeType
/**
The `NSAttributeType` for this type when used in `Select` clauses.
@@ -111,7 +111,7 @@ extension Bool: QueryableAttributeType {
@inline(__always)
public func cs_toQueryableNativeType() -> QueryableNativeType {
return self as NSNumber
return self as QueryableNativeType
}
}
@@ -133,7 +133,7 @@ extension CGFloat: QueryableAttributeType {
@inline(__always)
public func cs_toQueryableNativeType() -> QueryableNativeType {
return self as NSNumber
return self as QueryableNativeType
}
}
@@ -155,7 +155,7 @@ extension Data: QueryableAttributeType {
@inline(__always)
public func cs_toQueryableNativeType() -> QueryableNativeType {
return self as NSData
return self as QueryableNativeType
}
}
@@ -342,7 +342,10 @@ extension NSData: QueryableAttributeType {
public typealias QueryableNativeType = NSData
public static let cs_rawAttributeType: NSAttributeType = .binaryDataAttributeType
public class var cs_rawAttributeType: NSAttributeType {
return .binaryDataAttributeType
}
@nonobjc @inline(__always)
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
@@ -369,7 +372,10 @@ extension NSDate: QueryableAttributeType {
public typealias QueryableNativeType = NSDate
public static let cs_rawAttributeType: NSAttributeType = .dateAttributeType
public class var cs_rawAttributeType: NSAttributeType {
return .dateAttributeType
}
@nonobjc @inline(__always)
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
@@ -407,7 +413,10 @@ extension NSManagedObjectID: QueryableAttributeType {
public typealias QueryableNativeType = NSManagedObjectID
public static let cs_rawAttributeType: NSAttributeType = .objectIDAttributeType
public class var cs_rawAttributeType: NSAttributeType {
return .objectIDAttributeType
}
@nonobjc @inline(__always)
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
@@ -440,7 +449,7 @@ extension NSNull: QueryableAttributeType {
}
@nonobjc @inline(__always)
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
@inline(__always)
func forceCast<T: NSNull>(_ value: Any) -> T? {
@@ -494,7 +503,10 @@ extension NSString: QueryableAttributeType {
public typealias QueryableNativeType = NSString
public static let cs_rawAttributeType: NSAttributeType = .stringAttributeType
public class var cs_rawAttributeType: NSAttributeType {
return .stringAttributeType
}
@nonobjc @inline(__always)
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
@@ -521,10 +533,13 @@ extension NSURL: QueryableAttributeType {
public typealias QueryableNativeType = NSString
public static let cs_rawAttributeType: NSAttributeType = .stringAttributeType
public class var cs_rawAttributeType: NSAttributeType {
return .stringAttributeType
}
@nonobjc @inline(__always)
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
return self.init(string: value as String)
}
@@ -543,10 +558,13 @@ extension NSUUID: QueryableAttributeType {
public typealias QueryableNativeType = NSString
public static let cs_rawAttributeType: NSAttributeType = .stringAttributeType
public class var cs_rawAttributeType: NSAttributeType {
return .stringAttributeType
}
@nonobjc @inline(__always)
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
return self.init(uuidString: value.lowercased)
}
@@ -576,7 +594,7 @@ extension String: QueryableAttributeType {
@inline(__always)
public func cs_toQueryableNativeType() -> QueryableNativeType {
return self as NSString
return self as QueryableNativeType
}
}

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: KeyPath,
_ keyPath: RawKeyPath,
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: KeyPath,
_ keyPath: RawKeyPath,
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: KeyPath,
_ keyPath: RawKeyPath,
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: KeyPath,
_ keyPath: RawKeyPath,
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: KeyPath
public let keyPath: RawKeyPath
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: () -> KeyPath?)
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?)
internal let versionHashModifier: String?
internal let renamingIdentifier: String?
internal let affectedByKeyPaths: () -> Set<String>
@@ -286,7 +286,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: Private
private init(keyPath: KeyPath, inverseKeyPath: @escaping () -> KeyPath?, deleteRule: DeleteRule, versionHashModifier: String?, renamingIdentifier: String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
private init(keyPath: RawKeyPath, inverseKeyPath: @escaping () -> RawKeyPath?, deleteRule: DeleteRule, versionHashModifier: String?, renamingIdentifier: String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
self.keyPath = keyPath
self.deleteRule = deleteRule.nativeValue
@@ -333,7 +333,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: KeyPath,
_ keyPath: RawKeyPath,
minCount: Int = 0,
maxCount: Int = 0,
deleteRule: DeleteRule = .nullify,
@@ -373,7 +373,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: KeyPath,
_ keyPath: RawKeyPath,
minCount: Int = 0,
maxCount: Int = 0,
inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>,
@@ -414,7 +414,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: KeyPath,
_ keyPath: RawKeyPath,
minCount: Int = 0,
maxCount: Int = 0,
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>,
@@ -455,7 +455,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: KeyPath,
_ keyPath: RawKeyPath,
minCount: Int = 0,
maxCount: Int = 0,
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>,
@@ -494,7 +494,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: RelationshipProtocol
public let keyPath: KeyPath
public let keyPath: RawKeyPath
internal let isToMany = true
internal let isOptional = true
@@ -502,7 +502,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: () -> KeyPath?)
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?)
internal let versionHashModifier: String?
internal let renamingIdentifier: String?
internal let affectedByKeyPaths: () -> Set<String>
@@ -599,7 +599,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: KeyPath,
_ keyPath: RawKeyPath,
deleteRule: DeleteRule = .nullify,
minCount: Int = 0,
maxCount: Int = 0,
@@ -639,7 +639,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: KeyPath,
_ keyPath: RawKeyPath,
inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>,
deleteRule: DeleteRule = .nullify,
minCount: Int = 0,
@@ -680,7 +680,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: KeyPath,
_ keyPath: RawKeyPath,
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>,
deleteRule: DeleteRule = .nullify,
minCount: Int = 0,
@@ -721,7 +721,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: KeyPath,
_ keyPath: RawKeyPath,
inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>,
deleteRule: DeleteRule = .nullify,
minCount: Int = 0,
@@ -760,7 +760,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: RelationshipProtocol
public let keyPath: KeyPath
public let keyPath: RawKeyPath
internal let isToMany = true
internal let isOptional = true
@@ -768,7 +768,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: () -> KeyPath?)
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?)
internal let versionHashModifier: String?
internal let renamingIdentifier: String?
internal let affectedByKeyPaths: () -> Set<String>
@@ -813,7 +813,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: Private
private init(keyPath: KeyPath, inverseKeyPath: @escaping () -> KeyPath?, deleteRule: DeleteRule, minCount: Int, maxCount: Int, versionHashModifier: String?, renamingIdentifier: String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
private init(keyPath: RawKeyPath, inverseKeyPath: @escaping () -> RawKeyPath?, deleteRule: DeleteRule, minCount: Int, maxCount: Int, versionHashModifier: String?, renamingIdentifier: String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
self.keyPath = keyPath
self.deleteRule = deleteRule.nativeValue
@@ -1186,11 +1186,11 @@ extension RelationshipContainer.ToManyUnordered {
internal protocol RelationshipProtocol: class {
var keyPath: KeyPath { get }
var keyPath: RawKeyPath { get }
var isToMany: Bool { get }
var isOrdered: Bool { get }
var deleteRule: NSDeleteRule { get }
var inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPath?) { get }
var inverse: (type: CoreStoreObject.Type, keyPath: () -> RawKeyPath?) { get }
var affectedByKeyPaths: () -> Set<String> { get }
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: KeyPath) {
public init(_ sectionKeyPath: RawKeyPath) {
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: KeyPath, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) {
public init(_ sectionKeyPath: RawKeyPath, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) {
self.sectionKeyPath = sectionKeyPath
self.sectionIndexTransformer = sectionIndexTransformer
@@ -68,6 +68,6 @@ public struct SectionBy {
// MARK: Internal
internal let sectionKeyPath: KeyPath
internal let sectionKeyPath: RawKeyPath
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: KeyPath) -> SelectTerm {
public static func attribute(_ keyPath: RawKeyPath) -> 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: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
public static func average(_ keyPath: RawKeyPath, as alias: RawKeyPath? = 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: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
public static func count(_ keyPath: RawKeyPath, as alias: RawKeyPath? = 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: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
public static func maximum(_ keyPath: RawKeyPath, as alias: RawKeyPath? = 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: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
public static func minimum(_ keyPath: RawKeyPath, as alias: RawKeyPath? = 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: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
public static func sum(_ keyPath: RawKeyPath, as alias: RawKeyPath? = 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: KeyPath? = nil) -> SelectTerm {
public static func objectID(as alias: RawKeyPath? = nil) -> SelectTerm {
return ._identity(
alias: alias ?? "objectID",
@@ -213,17 +213,17 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
// MARK: ExpressibleByStringLiteral
public init(stringLiteral value: KeyPath) {
public init(stringLiteral value: RawKeyPath) {
self = ._attribute(value)
}
public init(unicodeScalarLiteral value: KeyPath) {
public init(unicodeScalarLiteral value: RawKeyPath) {
self = ._attribute(value)
}
public init(extendedGraphemeClusterLiteral value: KeyPath) {
public init(extendedGraphemeClusterLiteral value: RawKeyPath) {
self = ._attribute(value)
}
@@ -274,8 +274,8 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
// MARK: Internal
case _attribute(KeyPath)
case _aggregate(function: String, keyPath: KeyPath, alias: String, nativeType: NSAttributeType)
case _attribute(RawKeyPath)
case _aggregate(function: String, keyPath: RawKeyPath, 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() -> KeyPath {
internal func keyPathForFirstSelectTerm() -> RawKeyPath {
switch self.first! {

View File

@@ -117,7 +117,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: KeyPath,
_ keyPath: RawKeyPath,
`default`: V,
isIndexed: Bool = false,
isTransient: Bool = false,
@@ -130,7 +130,7 @@ public enum ValueContainer<O: CoreStoreObject> {
self.keyPath = keyPath
self.isIndexed = isIndexed
self.isTransient = isTransient
self.defaultValue = `default`.cs_toImportableNativeType()
self.defaultValue = `default`.cs_toQueryableNativeType()
self.versionHashModifier = versionHashModifier
self.renamingIdentifier = renamingIdentifier
self.customGetter = customGetter
@@ -156,7 +156,7 @@ public enum ValueContainer<O: CoreStoreObject> {
return object.rawObject!.getValue(
forKvcKey: self.keyPath,
didGetValue: { V.cs_fromImportableNativeType($0 as! V.ImportableNativeType)! }
didGetValue: { V.cs_fromQueryableNativeType($0 as! V.QueryableNativeType)! }
)
}
)
@@ -179,7 +179,7 @@ public enum ValueContainer<O: CoreStoreObject> {
object.rawObject!.setValue(
newValue,
forKvcKey: self.keyPath,
willSetValue: { $0.cs_toImportableNativeType() }
willSetValue: { $0.cs_toQueryableNativeType() }
)
},
newValue
@@ -195,7 +195,7 @@ public enum ValueContainer<O: CoreStoreObject> {
return V.cs_rawAttributeType
}
public let keyPath: KeyPath
public let keyPath: RawKeyPath
internal let isOptional = false
internal let isIndexed: Bool
@@ -262,7 +262,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: KeyPath,
_ keyPath: RawKeyPath,
`default`: V? = nil,
isIndexed: Bool = false,
isTransient: Bool = false,
@@ -275,7 +275,7 @@ public enum ValueContainer<O: CoreStoreObject> {
self.keyPath = keyPath
self.isIndexed = isIndexed
self.isTransient = isTransient
self.defaultValue = `default`?.cs_toImportableNativeType()
self.defaultValue = `default`?.cs_toQueryableNativeType()
self.versionHashModifier = versionHashModifier
self.renamingIdentifier = renamingIdentifier
self.customGetter = customGetter
@@ -301,7 +301,7 @@ public enum ValueContainer<O: CoreStoreObject> {
return object.rawObject!.getValue(
forKvcKey: self.keyPath,
didGetValue: { ($0 as! V.ImportableNativeType?).flatMap(V.cs_fromImportableNativeType) }
didGetValue: { ($0 as! V.QueryableNativeType?).flatMap(V.cs_fromQueryableNativeType) }
)
}
)
@@ -324,7 +324,7 @@ public enum ValueContainer<O: CoreStoreObject> {
object.rawObject!.setValue(
newValue,
forKvcKey: self.keyPath,
willSetValue: { $0?.cs_toImportableNativeType() }
willSetValue: { $0?.cs_toQueryableNativeType() }
)
},
newValue
@@ -340,7 +340,7 @@ public enum ValueContainer<O: CoreStoreObject> {
return V.cs_rawAttributeType
}
public let keyPath: KeyPath
public let keyPath: RawKeyPath
internal let isOptional = true
internal let isIndexed: Bool
internal let isTransient: Bool
@@ -386,7 +386,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: KeyPath,
_ keyPath: RawKeyPath,
isIndexed: Bool = false,
isTransient: Bool = false,
versionHashModifier: String? = nil,
@@ -462,7 +462,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: KeyPath,
_ keyPath: RawKeyPath,
`default`: V,
isIndexed: Bool = false,
isTransient: Bool = false,
@@ -539,7 +539,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
return .transformableAttributeType
}
public let keyPath: KeyPath
public let keyPath: RawKeyPath
internal let isOptional = false
internal let isIndexed: Bool
@@ -600,7 +600,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: KeyPath,
_ keyPath: RawKeyPath,
`default`: V? = nil,
isIndexed: Bool = false,
isTransient: Bool = false,
@@ -677,7 +677,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
return .transformableAttributeType
}
public let keyPath: KeyPath
public let keyPath: RawKeyPath
internal let isOptional = true
internal let isIndexed: Bool
@@ -995,7 +995,7 @@ internal protocol AttributeProtocol: class {
static var attributeType: NSAttributeType { get }
var keyPath: KeyPath { get }
var keyPath: RawKeyPath { get }
var isOptional: Bool { get }
var isIndexed: Bool { get }
var isTransient: Bool { get }

View File

@@ -109,7 +109,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: KeyPath, isEqualTo value: Void?) {
public init(_ keyPath: RawKeyPath, isEqualTo value: Void?) {
self.init(NSPredicate(format: "\(keyPath) == nil"))
}
@@ -120,7 +120,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: KeyPath, isEqualTo value: T?) {
public init<T: QueryableAttributeType>(_ keyPath: RawKeyPath, isEqualTo value: T?) {
switch value {
@@ -139,7 +139,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: KeyPath, isEqualTo object: T?) {
public init<T: DynamicObject>(_ keyPath: RawKeyPath, isEqualTo object: T?) {
switch object {
@@ -158,7 +158,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: KeyPath, isMemberOf list: S) where S.Iterator.Element: QueryableAttributeType {
public init<S: Sequence>(_ keyPath: RawKeyPath, isMemberOf list: S) where S.Iterator.Element: QueryableAttributeType {
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_toQueryableNativeType() }) as NSArray))
}
@@ -169,7 +169,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: KeyPath, isMemberOf list: S) where S.Iterator.Element: DynamicObject {
public init<S: Sequence>(_ keyPath: RawKeyPath, isMemberOf list: S) where S.Iterator.Element: DynamicObject {
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_id() }) as NSArray))
}