Coded

@propertyWrapper
public struct Coded<V> : AttributeKeyPathStringConvertible, FieldAttributeProtocol

The containing type for stored property values. Any type supported by the specified encoder/decoder are allowed.

class Animal: CoreStoreObject {

    @Field.Coded("eyeColor", coder: FieldCoders.NSCoding.self)
    var eyeColor: UIColor = .black

    @Field.Coded(
        "bloodType",
        coder: {
            encode: { $0.toData() },
            decode: { BloodType(fromData: $0) }
        }
    )
    var bloodType: BloodType = .unknown
}

Important

Field properties are required to be used as @propertyWrappers. Any other declaration not using the @Field.Stored(...) var syntax will be ignored.
  • Initializes the metadata for the property.

    class Person: CoreStoreObject {
    
        @Field.Coded("eyeColor", coder: FieldCoders.NSCoding.self)
        var eyeColor: UIColor = .black
    }
    

    Important

    Any changes in the coder are not reflected in the VersionLock, so make sure that the encoder and decoder logic is compatible for all versions of your persistent store.

    Declaration

    Swift

    public init<Coder: FieldCoderType>(
        wrappedValue initial: @autoclosure @escaping () -> V,
        _ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        coder fieldCoderType: Coder.Type = { fatalError("'coder' argument required (SR-13069 workaround)") }(),
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
    ) where Coder.FieldStoredValue == V

    Parameters

    initial

    the initial value for the property that is shared for all instances of this object. Note that this is evaluated during DataStack setup, not during object creation. To assign a value during object creation, use the dynamicInitialValue argument instead.

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    coder

    The FieldCoderType to be used for encoding and decoding the value

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

  • Initializes the metadata for the property.

    class Person: CoreStoreObject {
    
        @Field.Coded("eyeColor", coder: FieldCoders.NSCoding.self, dynamicInitialValue: { UIColor.random() })
        var eyeColor: UIColor
    }
    

    Important

    Any changes in the coder are not reflected in the VersionLock, so make sure that the encoder and decoder logic is compatible for all versions of your persistent store.

    Declaration

    Swift

    public init<Coder: FieldCoderType>(
        _ keyPath: KeyPathString,
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        coder fieldCoderType: Coder.Type,
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
        dynamicInitialValue: @escaping () -> V
    ) where Coder.FieldStoredValue == V

    Parameters

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    coder

    The FieldCoderType to be used for encoding and decoding the value

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

    dynamicInitialValue

    the initial value for the property when the object is first created.

  • Initializes the metadata for the property.

    class Person: CoreStoreObject {
    
        @Field.Coded(
            "bloodType",
            coder: {
                encode: { $0.toData() },
                decode: { BloodType(fromData: $0) }
            }
        )
        var bloodType: BloodType = .unknown
    }
    

    Important

    Any changes in the encoder/decoder are not reflected in the VersionLock, so make sure that the encoder and decoder logic is compatible for all versions of your persistent store.

    Declaration

    Swift

    public init(
        wrappedValue initial: @autoclosure @escaping () -> V,
        _ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        coder: (encode: (V) -> Data?, decode: (Data?) -> V) = { fatalError("'coder' argument required (SR-13069 workaround)") }(),
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
    )

    Parameters

    initial

    the initial value for the property that is shared for all instances of this object. Note that this is evaluated during DataStack setup, not during object creation. To assign a value during object creation, use the dynamicInitialValue argument instead.

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    coder

    The closures to be used for encoding and decoding the value

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

  • Initializes the metadata for the property.

    class Person: CoreStoreObject {
    
        @Field.Coded(
            "bloodType",
            coder: {
                encode: { $0.toData() },
                decode: { BloodType(fromData: $0) }
            },
            dynamicInitialValue: { BloodType.random() }
        )
        var bloodType: BloodType
    }
    

    Important

    Any changes in the encoder/decoder are not reflected in the VersionLock, so make sure that the encoder and decoder logic is compatible for all versions of your persistent store.

    Declaration

    Swift

    public init(
        _ keyPath: KeyPathString,
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        coder: (encode: (V) -> Data?, decode: (Data?) -> V),
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
        dynamicInitialValue: @escaping () -> V
    )

    Parameters

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    coder

    The closures to be used for encoding and decoding the value

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

    dynamicInitialValue

    the initial value for the property when the object is first created.

AnyKeyPathStringConvertible

  • Declaration

    Swift

    public var cs_keyPathString: String { get }

KeyPathStringConvertible

AttributeKeyPathStringConvertible

Available where V: FieldOptionalType

  • Initializes the metadata for the property.

    class Person: CoreStoreObject {
    
        @Field.Coded("eyeColor", coder: FieldCoders.NSCoding.self)
        var eyeColor: UIColor? = nil
    }
    

    Important

    Any changes in the coder are not reflected in the VersionLock, so make sure that the encoder and decoder logic is compatible for all versions of your persistent store.

    Declaration

    Swift

    public init<Coder: FieldCoderType>(
        wrappedValue initial: @autoclosure @escaping () -> V = nil,
        _ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        coder: Coder.Type = { fatalError("'coder' argument required (SR-13069 workaround)") }(),
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
    ) where Coder.FieldStoredValue == V.Wrapped

    Parameters

    initial

    the initial value for the property that is shared for all instances of this object. Note that this is evaluated during DataStack setup, not during object creation. To assign a value during object creation, use the dynamicInitialValue argument instead.

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    coder

    The FieldCoderType to be used for encoding and decoding the value

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

  • Initializes the metadata for the property.

    class Person: CoreStoreObject {
    
        @Field.Coded("eyeColor", coder: FieldCoders.NSCoding.self, dynamicInitialValue: { UIColor.random() })
        var eyeColor: UIColor?
    }
    

    Important

    Any changes in the coder are not reflected in the VersionLock, so make sure that the encoder and decoder logic is compatible for all versions of your persistent store.

    Declaration

    Swift

    public init<Coder: FieldCoderType>(
        _ keyPath: KeyPathString,
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        coder: Coder.Type,
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
        dynamicInitialValue: @escaping () -> V
    ) where Coder.FieldStoredValue == V.Wrapped

    Parameters

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    coder

    The FieldCoderType to be used for encoding and decoding the value

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

    dynamicInitialValue

    the initial value for the property when the object is first created.

  • Initializes the metadata for the property.

    class Person: CoreStoreObject {
    
        @Field.Coded(
            "bloodType",
            coder: {
                encode: { $0.toData() },
                decode: { BloodType(fromData: $0) }
            }
        )
        var bloodType: BloodType?
    }
    

    Important

    Any changes in the encoder/decoder are not reflected in the VersionLock, so make sure that the encoder and decoder logic is compatible for all versions of your persistent store.

    Declaration

    Swift

    public init(
        wrappedValue initial: @autoclosure @escaping () -> V = nil,
        _ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        coder: (encode: (V) -> Data?, decode: (Data?) -> V) = { fatalError("'coder' argument required (SR-13069 workaround)") }(),
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
    )

    Parameters

    initial

    the initial value for the property that is shared for all instances of this object. Note that this is evaluated during DataStack setup, not during object creation. To assign a value during object creation, use the dynamicInitialValue argument instead.

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    coder

    The closures to be used for encoding and decoding the value

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

  • Initializes the metadata for the property.

    class Person: CoreStoreObject {
    
        @Field.Coded(
            "bloodType",
            coder: {
                encode: { $0.toData() },
                decode: { BloodType(fromData: $0) }
            },
            dynamicInitialValue: { BloodType.random() }
        )
        var bloodType: BloodType?
    }
    

    Important

    Any changes in the encoder/decoder are not reflected in the VersionLock, so make sure that the encoder and decoder logic is compatible for all versions of your persistent store.

    Declaration

    Swift

    public init(
        _ keyPath: KeyPathString,
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        coder: (encode: (V) -> Data?, decode: (Data?) -> V),
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
        dynamicInitialValue: @escaping () -> V
    )

    Parameters

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    coder

    The closures to be used for encoding and decoding the value

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

    dynamicInitialValue

    the initial value for the property when the object is first created.

Available where V: DefaultNSSecureCodable

  • Initializes the metadata for the property. This overload is for types supported by Core Data’s default NSSecureCodable implementation: NSArray, NSDictionary, NSSet, NSString, NSNumber, NSDate, NSData, NSURL, NSUUID, and NSNull.

    class Person: CoreStoreObject {
    
        @Field.Coded("customInfo")
        var customInfo: NSDictionary = [:]
    }
    

    Declaration

    Swift

    public init(
        wrappedValue initial: @autoclosure @escaping () -> V,
        _ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
    )

    Parameters

    initial

    the initial value for the property that is shared for all instances of this object. Note that this is evaluated during DataStack setup, not during object creation. To assign a value during object creation, use the dynamicInitialValue argument instead.

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

  • Initializes the metadata for the property. This overload is for types supported by Core Data’s default NSSecureCodable implementation: NSArray, NSDictionary, NSSet, NSString, NSNumber, NSDate, NSData, NSURL, NSUUID, and NSNull.

    class Person: CoreStoreObject {
    
        @Field.Coded("customInfo", dynamicInitialValue: { ["id": UUID()] })
        var customInfo: NSDictionary
    }
    

    Declaration

    Swift

    public init(
        _ keyPath: KeyPathString,
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
        dynamicInitialValue: @escaping () -> V
    )

    Parameters

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

    dynamicInitialValue

    the initial value for the property when the object is first created.

Available where V: FieldOptionalType, V.Wrapped: DefaultNSSecureCodable

  • Initializes the metadata for the property. This overload is for types supported by Core Data’s default NSSecureCodable implementation: NSArray, NSDictionary, NSSet, NSString, NSNumber, NSDate, NSData, NSURL, NSUUID, and NSNull.

    class Person: CoreStoreObject {
    
        @Field.Coded("customInfo")
        var customInfo: NSDictionary? = nil
    }
    

    Declaration

    Swift

    public init(
        wrappedValue initial: @autoclosure @escaping () -> V = nil,
        _ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
    )

    Parameters

    initial

    the initial value for the property that is shared for all instances of this object. Note that this is evaluated during DataStack setup, not during object creation. To assign a value during object creation, use the dynamicInitialValue argument instead.

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

  • Initializes the metadata for the property. This overload is for types supported by Core Data’s default NSSecureCodable implementation: NSArray, NSDictionary, NSSet, NSString, NSNumber, NSDate, NSData, NSURL, NSUUID, and NSNull.

    class Person: CoreStoreObject {
    
        @Field.Coded("customInfo", dynamicInitialValue: { ["id": UUID()] })
        var customInfo: NSDictionary?
    }
    

    Declaration

    Swift

    public init(
        _ keyPath: KeyPathString,
        versionHashModifier: @autoclosure @escaping () -> String? = nil,
        previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
        customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
        customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
        affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
        dynamicInitialValue: @escaping () -> V
    )

    Parameters

    keyPath

    the permanent attribute name for this property.

    versionHashModifier

    used to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)

    previousVersionKeyPath

    used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property’s keyPath with a matching destination entity property’s previousVersionKeyPath indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’s keyPath.

    customGetter

    use this closure as an “override” for the default property getter. The closure receives a ObjectProxy<O>, which acts as a type-safe proxy for the receiver. When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively. Do not make assumptions on the thread/queue that the closure is executed on; accessors may be called from NSError logs for example.

    customSetter

    use this closure as an “override” for the default property setter. The closure receives a ObjectProxy<O>, which acts as a fast, type-safe KVC interface for CoreStoreObject. The reason a CoreStoreObject instance is not passed directly is because the Core Data runtime is not aware of CoreStoreObject properties’ static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as ListMonitor observing.) When accessing the property value from ObjectProxy<O>, make sure to use field.primitiveValue instead of field.value, which would unintentionally execute the same closure again recursively.

    affectedByKeyPaths

    a set of key paths for properties whose values affect the value of the receiver. This is similar to NSManagedObject.keyPathsForValuesAffectingValue(forKey:).

    dynamicInitialValue

    the initial value for the property when the object is first created.