mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-04-11 03:36:51 +02:00
lazily evaluate NSEntityDescription-required fields from CoreStoreObject attributes
This commit is contained in:
@@ -31,15 +31,18 @@ import CoreData
|
|||||||
|
|
||||||
internal protocol AttributeProtocol: PropertyProtocol {
|
internal protocol AttributeProtocol: PropertyProtocol {
|
||||||
|
|
||||||
static var attributeType: NSAttributeType { get }
|
typealias EntityDescriptionValues = (
|
||||||
|
attributeType: NSAttributeType,
|
||||||
|
isOptional: Bool,
|
||||||
|
isTransient: Bool,
|
||||||
|
allowsExternalBinaryDataStorage: Bool,
|
||||||
|
versionHashModifier: String?,
|
||||||
|
renamingIdentifier: String?,
|
||||||
|
affectedByKeyPaths: Set<String>,
|
||||||
|
defaultValue: Any?
|
||||||
|
)
|
||||||
|
|
||||||
var isOptional: Bool { get }
|
var entityDescriptionValues: () -> EntityDescriptionValues { get }
|
||||||
var isTransient: Bool { get }
|
|
||||||
var allowsExternalBinaryDataStorage: Bool { get }
|
|
||||||
var versionHashModifier: () -> String? { get }
|
|
||||||
var renamingIdentifier: () -> String? { get }
|
|
||||||
var defaultValue: () -> Any? { get }
|
|
||||||
var affectedByKeyPaths: () -> Set<String> { get }
|
|
||||||
var rawObject: CoreStoreManagedObject? { get set }
|
var rawObject: CoreStoreManagedObject? { get set }
|
||||||
var getter: CoreStoreManagedObject.CustomGetter? { get }
|
var getter: CoreStoreManagedObject.CustomGetter? { get }
|
||||||
var setter: CoreStoreManagedObject.CustomSetter? { get }
|
var setter: CoreStoreManagedObject.CustomSetter? { get }
|
||||||
|
|||||||
@@ -45,6 +45,17 @@ public final class CSError: NSError {
|
|||||||
@objc
|
@objc
|
||||||
public static let errorDomain = CoreStoreErrorDomain
|
public static let errorDomain = CoreStoreErrorDomain
|
||||||
|
|
||||||
|
public var bridgeToSwift: CoreStoreError {
|
||||||
|
|
||||||
|
if let swift = self.swiftError {
|
||||||
|
|
||||||
|
return swift
|
||||||
|
}
|
||||||
|
let swift = CoreStoreError(_bridgedNSError: self) ?? .unknown
|
||||||
|
self.swiftError = swift
|
||||||
|
return swift
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: NSObject
|
// MARK: NSObject
|
||||||
|
|
||||||
@@ -88,21 +99,7 @@ public final class CSError: NSError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
|
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
|
||||||
extension CSError: CoreStoreObjectiveCType {
|
extension CSError: CoreStoreObjectiveCType {}
|
||||||
|
|
||||||
// MARK: CoreStoreObjectiveCType
|
|
||||||
|
|
||||||
public var bridgeToSwift: CoreStoreError {
|
|
||||||
|
|
||||||
if let swift = self.swiftError {
|
|
||||||
|
|
||||||
return swift
|
|
||||||
}
|
|
||||||
let swift = CoreStoreError(_bridgedNSError: self) ?? .unknown
|
|
||||||
self.swiftError = swift
|
|
||||||
return swift
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - CSErrorCode
|
// MARK: - CSErrorCode
|
||||||
@@ -156,16 +153,7 @@ public enum CSErrorCode: Int {
|
|||||||
|
|
||||||
// MARK: - CoreStoreError
|
// MARK: - CoreStoreError
|
||||||
|
|
||||||
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
|
extension CoreStoreError: _ObjectiveCBridgeableError {
|
||||||
extension CoreStoreError: CoreStoreSwiftType, _ObjectiveCBridgeableError {
|
|
||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
|
||||||
|
|
||||||
public var bridgeToObjectiveC: CSError {
|
|
||||||
|
|
||||||
return CSError(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: _ObjectiveCBridgeableError
|
// MARK: _ObjectiveCBridgeableError
|
||||||
|
|
||||||
@@ -265,10 +253,12 @@ extension CoreStoreError: CoreStoreSwiftType, _ObjectiveCBridgeableError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: Internal
|
// MARK: - Error
|
||||||
|
|
||||||
extension Error {
|
extension Error {
|
||||||
|
|
||||||
|
// MARK: Internal
|
||||||
|
|
||||||
internal var bridgeToSwift: CoreStoreError {
|
internal var bridgeToSwift: CoreStoreError {
|
||||||
|
|
||||||
switch self {
|
switch self {
|
||||||
@@ -303,3 +293,17 @@ extension Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: - CoreStoreError
|
||||||
|
|
||||||
|
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
|
||||||
|
extension CoreStoreError: CoreStoreSwiftType {
|
||||||
|
|
||||||
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
|
public var bridgeToObjectiveC: CSError {
|
||||||
|
|
||||||
|
return CSError(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -292,17 +292,18 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
!NSManagedObject.instancesRespond(to: Selector(attribute.keyPath)),
|
!NSManagedObject.instancesRespond(to: Selector(attribute.keyPath)),
|
||||||
"Attribute Property name \"\(String(reflecting: entity.type)).\(attribute.keyPath)\" is not allowed because it collides with \"\(String(reflecting: NSManagedObject.self)).\(attribute.keyPath)\""
|
"Attribute Property name \"\(String(reflecting: entity.type)).\(attribute.keyPath)\" is not allowed because it collides with \"\(String(reflecting: NSManagedObject.self)).\(attribute.keyPath)\""
|
||||||
)
|
)
|
||||||
|
let entityDescriptionValues = attribute.entityDescriptionValues()
|
||||||
let description = NSAttributeDescription()
|
let description = NSAttributeDescription()
|
||||||
description.name = attribute.keyPath
|
description.name = attribute.keyPath
|
||||||
description.attributeType = Swift.type(of: attribute).attributeType
|
description.attributeType = entityDescriptionValues.attributeType
|
||||||
description.isOptional = attribute.isOptional
|
description.isOptional = entityDescriptionValues.isOptional
|
||||||
description.defaultValue = attribute.defaultValue()
|
description.defaultValue = entityDescriptionValues.defaultValue
|
||||||
description.isTransient = attribute.isTransient
|
description.isTransient = entityDescriptionValues.isTransient
|
||||||
description.allowsExternalBinaryDataStorage = attribute.allowsExternalBinaryDataStorage
|
description.allowsExternalBinaryDataStorage = entityDescriptionValues.allowsExternalBinaryDataStorage
|
||||||
description.versionHashModifier = attribute.versionHashModifier()
|
description.versionHashModifier = entityDescriptionValues.versionHashModifier
|
||||||
description.renamingIdentifier = attribute.renamingIdentifier()
|
description.renamingIdentifier = entityDescriptionValues.renamingIdentifier
|
||||||
propertyDescriptions.append(description)
|
propertyDescriptions.append(description)
|
||||||
keyPathsByAffectedKeyPaths[attribute.keyPath] = attribute.affectedByKeyPaths()
|
keyPathsByAffectedKeyPaths[attribute.keyPath] = entityDescriptionValues.affectedByKeyPaths
|
||||||
customGetterSetterByKeyPaths[attribute.keyPath] = (attribute.getter, attribute.setter)
|
customGetterSetterByKeyPaths[attribute.keyPath] = (attribute.getter, attribute.setter)
|
||||||
|
|
||||||
case let relationship as RelationshipProtocol:
|
case let relationship as RelationshipProtocol:
|
||||||
@@ -310,16 +311,17 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
!NSManagedObject.instancesRespond(to: Selector(relationship.keyPath)),
|
!NSManagedObject.instancesRespond(to: Selector(relationship.keyPath)),
|
||||||
"Relationship Property name \"\(String(reflecting: entity.type)).\(relationship.keyPath)\" is not allowed because it collides with \"\(String(reflecting: NSManagedObject.self)).\(relationship.keyPath)\""
|
"Relationship Property name \"\(String(reflecting: entity.type)).\(relationship.keyPath)\" is not allowed because it collides with \"\(String(reflecting: NSManagedObject.self)).\(relationship.keyPath)\""
|
||||||
)
|
)
|
||||||
|
let entityDescriptionValues = relationship.entityDescriptionValues()
|
||||||
let description = NSRelationshipDescription()
|
let description = NSRelationshipDescription()
|
||||||
description.name = relationship.keyPath
|
description.name = relationship.keyPath
|
||||||
description.minCount = relationship.minCount
|
description.minCount = entityDescriptionValues.minCount
|
||||||
description.maxCount = relationship.maxCount
|
description.maxCount = entityDescriptionValues.maxCount
|
||||||
description.isOrdered = relationship.isOrdered
|
description.isOrdered = entityDescriptionValues.isOrdered
|
||||||
description.deleteRule = relationship.deleteRule
|
description.deleteRule = entityDescriptionValues.deleteRule
|
||||||
description.versionHashModifier = relationship.versionHashModifier()
|
description.versionHashModifier = entityDescriptionValues.versionHashModifier
|
||||||
description.renamingIdentifier = relationship.renamingIdentifier()
|
description.renamingIdentifier = entityDescriptionValues.renamingIdentifier
|
||||||
propertyDescriptions.append(description)
|
propertyDescriptions.append(description)
|
||||||
keyPathsByAffectedKeyPaths[relationship.keyPath] = relationship.affectedByKeyPaths()
|
keyPathsByAffectedKeyPaths[relationship.keyPath] = entityDescriptionValues.affectedByKeyPaths
|
||||||
|
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
@@ -384,12 +386,12 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
switch property {
|
switch property {
|
||||||
|
|
||||||
case let relationship as RelationshipProtocol:
|
case let relationship as RelationshipProtocol:
|
||||||
let (destinationType, destinationKeyPath) = relationship.inverse
|
let (destinationType, destinationKeyPath) = relationship.entityDescriptionValues().inverse
|
||||||
let destinationEntity = findEntity(for: destinationType)
|
let destinationEntity = findEntity(for: destinationType)
|
||||||
let description = relationshipsByName[relationship.keyPath]!
|
let description = relationshipsByName[relationship.keyPath]!
|
||||||
description.destinationEntity = entityDescriptionsByEntity[destinationEntity]!
|
description.destinationEntity = entityDescriptionsByEntity[destinationEntity]!
|
||||||
|
|
||||||
if let destinationKeyPath = destinationKeyPath() {
|
if let destinationKeyPath = destinationKeyPath {
|
||||||
|
|
||||||
let inverseRelationshipDescription = findInverseRelationshipMatching(
|
let inverseRelationshipDescription = findInverseRelationshipMatching(
|
||||||
destinationEntity: destinationEntity,
|
destinationEntity: destinationEntity,
|
||||||
|
|||||||
@@ -258,15 +258,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: RelationshipProtocol
|
// MARK: RelationshipProtocol
|
||||||
|
|
||||||
internal let isToMany = false
|
internal let entityDescriptionValues: () -> RelationshipProtocol.EntityDescriptionValues
|
||||||
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: () -> KeyPathString?)
|
|
||||||
internal let versionHashModifier: () -> String?
|
|
||||||
internal let renamingIdentifier: () -> String?
|
|
||||||
internal let affectedByKeyPaths: () -> Set<String>
|
|
||||||
internal var rawObject: CoreStoreManagedObject?
|
internal var rawObject: CoreStoreManagedObject?
|
||||||
|
|
||||||
internal var nativeValue: NSManagedObject? {
|
internal var nativeValue: NSManagedObject? {
|
||||||
@@ -324,11 +316,19 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
private init(keyPath: KeyPathString, inverseKeyPath: @escaping () -> KeyPathString?, deleteRule: DeleteRule, versionHashModifier: @autoclosure @escaping () -> String?, renamingIdentifier: @autoclosure @escaping () -> String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
|
private init(keyPath: KeyPathString, inverseKeyPath: @escaping () -> KeyPathString?, deleteRule: DeleteRule, versionHashModifier: @autoclosure @escaping () -> String?, renamingIdentifier: @autoclosure @escaping () -> String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.deleteRule = deleteRule.nativeValue
|
self.entityDescriptionValues = {
|
||||||
self.inverse = (D.self, inverseKeyPath)
|
(
|
||||||
self.versionHashModifier = versionHashModifier
|
isToMany: false,
|
||||||
self.renamingIdentifier = renamingIdentifier
|
isOrdered: false,
|
||||||
self.affectedByKeyPaths = affectedByKeyPaths
|
deleteRule: deleteRule.nativeValue,
|
||||||
|
inverse: (type: D.self, keyPath: inverseKeyPath()),
|
||||||
|
versionHashModifier: versionHashModifier(),
|
||||||
|
renamingIdentifier: renamingIdentifier(),
|
||||||
|
affectedByKeyPaths: affectedByKeyPaths(),
|
||||||
|
minCount: 0,
|
||||||
|
maxCount: 1
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,16 +553,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: RelationshipProtocol
|
// MARK: RelationshipProtocol
|
||||||
|
|
||||||
internal let isToMany = true
|
internal let entityDescriptionValues: () -> RelationshipProtocol.EntityDescriptionValues
|
||||||
internal let isOptional = true
|
|
||||||
internal let isOrdered = true
|
|
||||||
internal let deleteRule: NSDeleteRule
|
|
||||||
internal let minCount: Int
|
|
||||||
internal let maxCount: Int
|
|
||||||
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPathString?)
|
|
||||||
internal let versionHashModifier: () -> String?
|
|
||||||
internal let renamingIdentifier: () -> String?
|
|
||||||
internal let affectedByKeyPaths: () -> Set<String>
|
|
||||||
internal var rawObject: CoreStoreManagedObject?
|
internal var rawObject: CoreStoreManagedObject?
|
||||||
|
|
||||||
internal var nativeValue: NSOrderedSet {
|
internal var nativeValue: NSOrderedSet {
|
||||||
@@ -620,15 +611,20 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
private init(keyPath: String, minCount: Int, maxCount: Int, inverseKeyPath: @escaping () -> String?, deleteRule: DeleteRule, versionHashModifier: @autoclosure @escaping () -> String?, renamingIdentifier: @autoclosure @escaping () -> String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
|
private init(keyPath: String, minCount: Int, maxCount: Int, inverseKeyPath: @escaping () -> String?, deleteRule: DeleteRule, versionHashModifier: @autoclosure @escaping () -> String?, renamingIdentifier: @autoclosure @escaping () -> String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.deleteRule = deleteRule.nativeValue
|
self.entityDescriptionValues = {
|
||||||
self.inverse = (D.self, inverseKeyPath)
|
let range = (Swift.max(0, minCount) ... maxCount)
|
||||||
self.versionHashModifier = versionHashModifier
|
return (
|
||||||
self.renamingIdentifier = renamingIdentifier
|
isToMany: true,
|
||||||
|
isOrdered: true,
|
||||||
let range = (Swift.max(0, minCount) ... maxCount)
|
deleteRule: deleteRule.nativeValue,
|
||||||
self.minCount = range.lowerBound
|
inverse: (type: D.self, keyPath: inverseKeyPath()),
|
||||||
self.maxCount = range.upperBound
|
versionHashModifier: versionHashModifier(),
|
||||||
self.affectedByKeyPaths = affectedByKeyPaths
|
renamingIdentifier: renamingIdentifier(),
|
||||||
|
affectedByKeyPaths: affectedByKeyPaths(),
|
||||||
|
minCount: range.lowerBound,
|
||||||
|
maxCount: range.upperBound
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -854,16 +850,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: RelationshipProtocol
|
// MARK: RelationshipProtocol
|
||||||
|
|
||||||
internal let isToMany = true
|
internal let entityDescriptionValues: () -> RelationshipProtocol.EntityDescriptionValues
|
||||||
internal let isOptional = true
|
|
||||||
internal let isOrdered = false
|
|
||||||
internal let deleteRule: NSDeleteRule
|
|
||||||
internal let minCount: Int
|
|
||||||
internal let maxCount: Int
|
|
||||||
internal let inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPathString?)
|
|
||||||
internal let versionHashModifier: () -> String?
|
|
||||||
internal let renamingIdentifier: () -> String?
|
|
||||||
internal let affectedByKeyPaths: () -> Set<String>
|
|
||||||
internal var rawObject: CoreStoreManagedObject?
|
internal var rawObject: CoreStoreManagedObject?
|
||||||
|
|
||||||
internal var nativeValue: NSSet {
|
internal var nativeValue: NSSet {
|
||||||
@@ -921,15 +908,20 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
|||||||
private init(keyPath: KeyPathString, inverseKeyPath: @escaping () -> KeyPathString?, deleteRule: DeleteRule, minCount: Int, maxCount: Int, versionHashModifier: @autoclosure @escaping () -> String?, renamingIdentifier: @autoclosure @escaping () -> String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
|
private init(keyPath: KeyPathString, inverseKeyPath: @escaping () -> KeyPathString?, deleteRule: DeleteRule, minCount: Int, maxCount: Int, versionHashModifier: @autoclosure @escaping () -> String?, renamingIdentifier: @autoclosure @escaping () -> String?, affectedByKeyPaths: @autoclosure @escaping () -> Set<String>) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.deleteRule = deleteRule.nativeValue
|
self.entityDescriptionValues = {
|
||||||
self.inverse = (D.self, inverseKeyPath)
|
let range = (Swift.max(0, minCount) ... maxCount)
|
||||||
self.versionHashModifier = versionHashModifier
|
return (
|
||||||
self.renamingIdentifier = renamingIdentifier
|
isToMany: true,
|
||||||
|
isOrdered: false,
|
||||||
let range = (Swift.max(0, minCount) ... maxCount)
|
deleteRule: deleteRule.nativeValue,
|
||||||
self.minCount = range.lowerBound
|
inverse: (type: D.self, keyPath: inverseKeyPath()),
|
||||||
self.maxCount = range.upperBound
|
versionHashModifier: versionHashModifier(),
|
||||||
self.affectedByKeyPaths = affectedByKeyPaths
|
renamingIdentifier: renamingIdentifier(),
|
||||||
|
affectedByKeyPaths: affectedByKeyPaths(),
|
||||||
|
minCount: range.lowerBound,
|
||||||
|
maxCount: range.upperBound
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,15 +31,20 @@ import CoreData
|
|||||||
|
|
||||||
internal protocol RelationshipProtocol: PropertyProtocol {
|
internal protocol RelationshipProtocol: PropertyProtocol {
|
||||||
|
|
||||||
var isToMany: Bool { get }
|
typealias EntityDescriptionValues = (
|
||||||
var isOrdered: Bool { get }
|
isToMany: Bool,
|
||||||
var deleteRule: NSDeleteRule { get }
|
isOrdered: Bool,
|
||||||
var inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPathString?) { get }
|
deleteRule: NSDeleteRule,
|
||||||
var affectedByKeyPaths: () -> Set<String> { get }
|
inverse: (type: CoreStoreObject.Type, KeyPathString?),
|
||||||
|
versionHashModifier: String?,
|
||||||
|
renamingIdentifier: String?,
|
||||||
|
affectedByKeyPaths: Set<String>,
|
||||||
|
minCount: Int,
|
||||||
|
maxCount: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
var entityDescriptionValues: () -> EntityDescriptionValues { get }
|
||||||
|
|
||||||
var rawObject: CoreStoreManagedObject? { get set }
|
var rawObject: CoreStoreManagedObject? { get set }
|
||||||
var versionHashModifier: () -> String? { get }
|
|
||||||
var renamingIdentifier: () -> String? { get }
|
|
||||||
var minCount: Int { get }
|
|
||||||
var maxCount: Int { get }
|
|
||||||
var valueForSnapshot: Any? { get }
|
var valueForSnapshot: Any? { get }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,14 +127,20 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.defaultValue = initial
|
self.entityDescriptionValues = {
|
||||||
self.isTransient = isTransient
|
(
|
||||||
self.allowsExternalBinaryDataStorage = allowsExternalBinaryDataStorage
|
attributeType: .transformableAttributeType,
|
||||||
self.versionHashModifier = versionHashModifier
|
isOptional: false,
|
||||||
self.renamingIdentifier = renamingIdentifier
|
isTransient: isTransient,
|
||||||
|
allowsExternalBinaryDataStorage: allowsExternalBinaryDataStorage,
|
||||||
|
versionHashModifier: versionHashModifier(),
|
||||||
|
renamingIdentifier: renamingIdentifier(),
|
||||||
|
affectedByKeyPaths: affectedByKeyPaths(),
|
||||||
|
defaultValue: initial()
|
||||||
|
)
|
||||||
|
}
|
||||||
self.customGetter = customGetter
|
self.customGetter = customGetter
|
||||||
self.customSetter = customSetter
|
self.customSetter = customSetter
|
||||||
self.affectedByKeyPaths = affectedByKeyPaths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -216,18 +222,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: AttributeProtocol
|
// MARK: AttributeProtocol
|
||||||
|
|
||||||
internal static var attributeType: NSAttributeType {
|
internal let entityDescriptionValues: () -> AttributeProtocol.EntityDescriptionValues
|
||||||
|
|
||||||
return .transformableAttributeType
|
|
||||||
}
|
|
||||||
|
|
||||||
internal let isOptional = false
|
|
||||||
internal let isTransient: Bool
|
|
||||||
internal let allowsExternalBinaryDataStorage: Bool
|
|
||||||
internal let versionHashModifier: () -> String?
|
|
||||||
internal let renamingIdentifier: () -> String?
|
|
||||||
internal let defaultValue: () -> Any?
|
|
||||||
internal let affectedByKeyPaths: () -> Set<String>
|
|
||||||
internal var rawObject: CoreStoreManagedObject?
|
internal var rawObject: CoreStoreManagedObject?
|
||||||
|
|
||||||
internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in
|
internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in
|
||||||
@@ -349,14 +344,20 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.defaultValue = initial
|
self.entityDescriptionValues = {
|
||||||
self.isTransient = isTransient
|
(
|
||||||
self.allowsExternalBinaryDataStorage = allowsExternalBinaryDataStorage
|
attributeType: .transformableAttributeType,
|
||||||
self.versionHashModifier = versionHashModifier
|
isOptional: true,
|
||||||
self.renamingIdentifier = renamingIdentifier
|
isTransient: isTransient,
|
||||||
|
allowsExternalBinaryDataStorage: allowsExternalBinaryDataStorage,
|
||||||
|
versionHashModifier: versionHashModifier(),
|
||||||
|
renamingIdentifier: renamingIdentifier(),
|
||||||
|
affectedByKeyPaths: affectedByKeyPaths(),
|
||||||
|
defaultValue: initial()
|
||||||
|
)
|
||||||
|
}
|
||||||
self.customGetter = customGetter
|
self.customGetter = customGetter
|
||||||
self.customSetter = customSetter
|
self.customSetter = customSetter
|
||||||
self.affectedByKeyPaths = affectedByKeyPaths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -438,18 +439,7 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: AttributeProtocol
|
// MARK: AttributeProtocol
|
||||||
|
|
||||||
internal static var attributeType: NSAttributeType {
|
internal let entityDescriptionValues: () -> AttributeProtocol.EntityDescriptionValues
|
||||||
|
|
||||||
return .transformableAttributeType
|
|
||||||
}
|
|
||||||
|
|
||||||
internal let isOptional = true
|
|
||||||
internal let isTransient: Bool
|
|
||||||
internal let allowsExternalBinaryDataStorage: Bool
|
|
||||||
internal let versionHashModifier: () -> String?
|
|
||||||
internal let renamingIdentifier: () -> String?
|
|
||||||
internal let defaultValue: () -> Any?
|
|
||||||
internal let affectedByKeyPaths: () -> Set<String>
|
|
||||||
internal var rawObject: CoreStoreManagedObject?
|
internal var rawObject: CoreStoreManagedObject?
|
||||||
|
|
||||||
internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in
|
internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in
|
||||||
|
|||||||
@@ -121,13 +121,20 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.isTransient = isTransient
|
self.entityDescriptionValues = {
|
||||||
self.defaultValue = { initial().cs_toQueryableNativeType() }
|
(
|
||||||
self.versionHashModifier = versionHashModifier
|
attributeType: V.cs_rawAttributeType,
|
||||||
self.renamingIdentifier = renamingIdentifier
|
isOptional: false,
|
||||||
|
isTransient: isTransient,
|
||||||
|
allowsExternalBinaryDataStorage: false,
|
||||||
|
versionHashModifier: versionHashModifier(),
|
||||||
|
renamingIdentifier: renamingIdentifier(),
|
||||||
|
affectedByKeyPaths: affectedByKeyPaths(),
|
||||||
|
defaultValue: initial().cs_toQueryableNativeType()
|
||||||
|
)
|
||||||
|
}
|
||||||
self.customGetter = customGetter
|
self.customGetter = customGetter
|
||||||
self.customSetter = customSetter
|
self.customSetter = customSetter
|
||||||
self.affectedByKeyPaths = affectedByKeyPaths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,18 +218,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: AttributeProtocol
|
// MARK: AttributeProtocol
|
||||||
|
|
||||||
internal static var attributeType: NSAttributeType {
|
internal let entityDescriptionValues: () -> AttributeProtocol.EntityDescriptionValues
|
||||||
|
|
||||||
return V.cs_rawAttributeType
|
|
||||||
}
|
|
||||||
|
|
||||||
internal let isOptional = false
|
|
||||||
internal let isTransient: Bool
|
|
||||||
internal let allowsExternalBinaryDataStorage = false
|
|
||||||
internal let versionHashModifier: () -> String?
|
|
||||||
internal let renamingIdentifier: () -> String?
|
|
||||||
internal let defaultValue: () -> Any?
|
|
||||||
internal let affectedByKeyPaths: () -> Set<String>
|
|
||||||
internal var rawObject: CoreStoreManagedObject?
|
internal var rawObject: CoreStoreManagedObject?
|
||||||
|
|
||||||
internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in
|
internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in
|
||||||
@@ -344,13 +340,20 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.isTransient = isTransient
|
self.entityDescriptionValues = {
|
||||||
self.defaultValue = { initial()?.cs_toQueryableNativeType() }
|
(
|
||||||
self.versionHashModifier = versionHashModifier
|
attributeType: V.cs_rawAttributeType,
|
||||||
self.renamingIdentifier = renamingIdentifier
|
isOptional: true,
|
||||||
|
isTransient: isTransient,
|
||||||
|
allowsExternalBinaryDataStorage: false,
|
||||||
|
versionHashModifier: versionHashModifier(),
|
||||||
|
renamingIdentifier: renamingIdentifier(),
|
||||||
|
affectedByKeyPaths: affectedByKeyPaths(),
|
||||||
|
defaultValue: initial()?.cs_toQueryableNativeType()
|
||||||
|
)
|
||||||
|
}
|
||||||
self.customGetter = customGetter
|
self.customGetter = customGetter
|
||||||
self.customSetter = customSetter
|
self.customSetter = customSetter
|
||||||
self.affectedByKeyPaths = affectedByKeyPaths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -433,18 +436,7 @@ public enum ValueContainer<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: AttributeProtocol
|
// MARK: AttributeProtocol
|
||||||
|
|
||||||
internal static var attributeType: NSAttributeType {
|
internal let entityDescriptionValues: () -> AttributeProtocol.EntityDescriptionValues
|
||||||
|
|
||||||
return V.cs_rawAttributeType
|
|
||||||
}
|
|
||||||
|
|
||||||
internal let isOptional = true
|
|
||||||
internal let isTransient: Bool
|
|
||||||
internal let allowsExternalBinaryDataStorage = false
|
|
||||||
internal let versionHashModifier: () -> String?
|
|
||||||
internal let renamingIdentifier: () -> String?
|
|
||||||
internal let defaultValue: () -> Any?
|
|
||||||
internal let affectedByKeyPaths: () -> Set<String>
|
|
||||||
internal var rawObject: CoreStoreManagedObject?
|
internal var rawObject: CoreStoreManagedObject?
|
||||||
|
|
||||||
internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in
|
internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in
|
||||||
|
|||||||
Reference in New Issue
Block a user