Stored
@propertyWrapper
public struct Stored<V> : AttributeKeyPathStringConvertible, FieldAttributeProtocol where V : FieldStorableType
The containing type for stored property values. Any type that conforms to FieldStorableType
are supported.
class Person: CoreStoreObject {
@Field.Stored("title")
var title: String = "Mr."
@Field.Stored("nickname")
var nickname: String?
}
Important
Field
properties are required to be used as @propertyWrapper
s. Any other declaration not using the @Field.Stored(...) var
syntax will be ignored.
-
init(wrappedValue:
_: versionHashModifier: previousVersionKeyPath: customGetter: customSetter: affectedByKeyPaths: ) Initializes the metadata for the property.
class Person: CoreStoreObject { @Field.Stored("title") var title: String = "Mr." }
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 thedynamicInitialValue
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’spreviousVersionKeyPath
indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’skeyPath
.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 fromObjectProxy<O>
, make sure to usefield.primitiveValue
instead offield.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 fromNSError
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 forCoreStoreObject
. The reason aCoreStoreObject
instance is not passed directly is because the Core Data runtime is not aware ofCoreStoreObject
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 asListMonitor
observing.) When accessing the property value fromObjectProxy<O>
, make sure to usefield.primitiveValue
instead offield.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:)
. -
init(_:
versionHashModifier: previousVersionKeyPath: customGetter: customSetter: affectedByKeyPaths: dynamicInitialValue: ) Initializes the metadata for the property.
class Person: CoreStoreObject { @Field.Stored("title", dynamicInitialValue: { Person.randomTitle() }) var title: String }
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’spreviousVersionKeyPath
indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’skeyPath
.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 fromObjectProxy<O>
, make sure to usefield.primitiveValue
instead offield.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 fromNSError
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 forCoreStoreObject
. The reason aCoreStoreObject
instance is not passed directly is because the Core Data runtime is not aware ofCoreStoreObject
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 asListMonitor
observing.) When accessing the property value fromObjectProxy<O>
, make sure to usefield.primitiveValue
instead offield.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.
-
Declaration
Swift
public var cs_keyPathString: String { get }
-
Declaration
Swift
public typealias ObjectType = O
-
Declaration
Swift
public typealias DestinationValueType = V
-
Declaration
Swift
public typealias ReturnValueType = DestinationValueType
-
Creates a
Where
clause by checking if a sequence contains the value of a propertylet dog = dataStack.fetchOne(From<Dog>().where({ ["Pluto", "Snoopy", "Scooby"] ~= $0.nickname }))
Declaration
Swift
public static func ~= <S>(sequence: S, attribute: `Self`) -> Where<O> where V == S.Element, S : Sequence
-
init(wrappedValue:
_: versionHashModifier: previousVersionKeyPath: customGetter: customSetter: affectedByKeyPaths: ) Initializes the metadata for the property.
class Person: CoreStoreObject { @Field.Stored("nickname") var nickname: String? }
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 thedynamicInitialValue
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’spreviousVersionKeyPath
indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’skeyPath
.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 fromObjectProxy<O>
, make sure to usefield.primitiveValue
instead offield.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 fromNSError
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 forCoreStoreObject
. The reason aCoreStoreObject
instance is not passed directly is because the Core Data runtime is not aware ofCoreStoreObject
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 asListMonitor
observing.) When accessing the property value fromObjectProxy<O>
, make sure to usefield.primitiveValue
instead offield.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:)
. -
init(_:
versionHashModifier: previousVersionKeyPath: customGetter: customSetter: affectedByKeyPaths: dynamicInitialValue: ) Initializes the metadata for the property.
class Person: CoreStoreObject { @Field.Stored("nickname", dynamicInitialValue: { Person.randomNickname() }) var nickname: String? }
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’spreviousVersionKeyPath
indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property’skeyPath
.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 fromObjectProxy<O>
, make sure to usefield.primitiveValue
instead offield.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 fromNSError
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 forCoreStoreObject
. The reason aCoreStoreObject
instance is not passed directly is because the Core Data runtime is not aware ofCoreStoreObject
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 asListMonitor
observing.) When accessing the property value fromObjectProxy<O>
, make sure to usefield.primitiveValue
instead offield.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.