ToOne
public final class ToOne<D> : RelationshipKeyPathStringConvertible, RelationshipProtocol where D : CoreStoreObject
The containing type for to-one relationships. Any CoreStoreObject subclass can be a destination type. Inverse relationships should be declared from the destination type as well, using the inverse: argument for the relationship.
class Dog: CoreStoreObject {
let master = Relationship.ToOne<Person>("master")
}
class Person: CoreStoreObject {
let pets = Relationship.ToManyUnordered<Dog>("pets", inverse: { $0.master })
}
Important
Relationship.ToOne properties are required to be stored properties. Computed properties will be ignored, including lazy and weak properties.
-
Initializes the metadata for the relationship. All relationships require an “inverse”, so updates to to this object’s relationship are also reflected on its destination object. Make sure to declare this relationship’s inverse relationship on its destination object. Due to Swift’s compiler limitation, only one of the relationship and its inverse can declare an
inverse:argument.class Dog: CoreStoreObject { let master = Relationship.ToOne<Person>("master") } class Person: CoreStoreObject { let pets = Relationship.ToManyUnordered<Dog>("pets", inverse: { $0.master }) }Declaration
Swift
public convenience init( _ keyPath: KeyPathString, deleteRule: DeleteRule = .nullify, versionHashModifier: @autoclosure @escaping () -> String? = nil, renamingIdentifier: @autoclosure @escaping () -> String? = nil, affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = [])Parameters
keyPaththe permanent name for this relationship.
deleteRuledefines what happens to relationship when an object is deleted. Valid values are
.nullify,.cascade, and.delete. Defaults to.nullify.versionHashModifierused to mark or denote a relationship 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.)
renamingIdentifierused to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property and a destination entity property that share the same identifier 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 name.
affectedByKeyPathsa 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 relationship. All relationships require an “inverse”, so updates to to this object’s relationship are also reflected on its destination object. Make sure to declare this relationship’s inverse relationship on its destination object. Due to Swift’s compiler limitation, only one of the relationship and its inverse can declare an
inverse:argument.class Dog: CoreStoreObject { let master = Relationship.ToOne<Person>("master") } class Person: CoreStoreObject { let pets = Relationship.ToManyUnordered<Dog>("pets", inverse: { $0.master }) }Declaration
Swift
public convenience init( _ keyPath: KeyPathString, inverse: @escaping (D) -> RelationshipContainer<D>.ToOne<O>, deleteRule: DeleteRule = .nullify, versionHashModifier: @autoclosure @escaping () -> String? = nil, renamingIdentifier: @autoclosure @escaping () -> String? = nil, affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = [])Parameters
keyPaththe permanent name for this relationship.
inversethe inverse relationship that is declared for the destination object. All relationships require an “inverse”, so updates to to this object’s relationship are also reflected on its destination object.
deleteRuledefines what happens to relationship when an object is deleted. Valid values are
.nullify,.cascade, and.delete. Defaults to.nullify.versionHashModifierused to mark or denote a relationship 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.)
renamingIdentifierused to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property and a destination entity property that share the same identifier 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 name.
affectedByKeyPathsa 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 relationship. All relationships require an “inverse”, so updates to to this object’s relationship are also reflected on its destination object. Make sure to declare this relationship’s inverse relationship on its destination object. Due to Swift’s compiler limitation, only one of the relationship and its inverse can declare an
inverse:argument.class Dog: CoreStoreObject { let master = Relationship.ToOne<Person>("master") } class Person: CoreStoreObject { let pets = Relationship.ToManyUnordered<Dog>("pets", inverse: { $0.master }) }Declaration
Swift
public convenience init( _ keyPath: KeyPathString, inverse: @escaping (D) -> RelationshipContainer<D>.ToManyOrdered<O>, deleteRule: DeleteRule = .nullify, versionHashModifier: @autoclosure @escaping () -> String? = nil, renamingIdentifier: @autoclosure @escaping () -> String? = nil, affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = [])Parameters
keyPaththe permanent name for this relationship.
inversethe inverse relationship that is declared for the destination object. All relationships require an “inverse”, so updates to to this object’s relationship are also reflected on its destination object.
deleteRuledefines what happens to relationship when an object is deleted. Valid values are
.nullify,.cascade, and.delete. Defaults to.nullify.versionHashModifierused to mark or denote a relationship 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.)
renamingIdentifierused to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property and a destination entity property that share the same identifier 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 name.
affectedByKeyPathsa 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 relationship. All relationships require an “inverse”, so updates to to this object’s relationship are also reflected on its destination object. Make sure to declare this relationship’s inverse relationship on its destination object. Due to Swift’s compiler limitation, only one of the relationship and its inverse can declare an
inverse:argument.class Dog: CoreStoreObject { let master = Relationship.ToOne<Person>("master") } class Person: CoreStoreObject { let pets = Relationship.ToManyUnordered<Dog>("pets", inverse: { $0.master }) }Declaration
Swift
public convenience init( _ keyPath: KeyPathString, inverse: @escaping (D) -> RelationshipContainer<D>.ToManyUnordered<O>, deleteRule: DeleteRule = .nullify, versionHashModifier: @autoclosure @escaping () -> String? = nil, renamingIdentifier: @autoclosure @escaping () -> String? = nil, affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = [])Parameters
keyPaththe permanent name for this relationship.
inversethe inverse relationship that is declared for the destination object. All relationships require an “inverse”, so updates to to this object’s relationship are also reflected on its destination object.
deleteRuledefines what happens to relationship when an object is deleted. Valid values are
.nullify,.cascade, and.delete. Defaults to.nullify.versionHashModifierused to mark or denote a relationship 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.)
renamingIdentifierused to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property and a destination entity property that share the same identifier 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 name.
affectedByKeyPathsa set of key paths for properties whose values affect the value of the receiver. This is similar to
NSManagedObject.keyPathsForValuesAffectingValue(forKey:). -
The relationship value
Declaration
Swift
public var value: ReturnValueType { get set }
-
Declaration
Swift
public var cs_keyPathString: String { get }
-
Declaration
Swift
public typealias ObjectType = O -
Declaration
Swift
public typealias DestinationValueType = D
-
Declaration
Swift
public typealias ReturnValueType = DestinationValueType?
-
Observes changes in the receiver value. When the returned
CoreStoreObjectKeyValueObservationis deinited or invalidated, it will stop observing.Declaration
Swift
public func observe(options: NSKeyValueObservingOptions = [], changeHandler: @escaping (O, CoreStoreObjectObjectDiff<D>) -> Void) -> CoreStoreObjectKeyValueObservationParameters
optionsThe flags indicating which values to include in the change dictionary.
-
Creates a
Whereclause by comparing if a property is equal to a valuelet dog = dataStack.fetchOne(From<Dog>().where({ $0.master == me }))Declaration
Swift
public static func == (relationship: RelationshipContainer<O>.ToOne<D>, object: D?) -> Where<O> -
Creates a
Whereclause by comparing if a property is not equal to a valuelet dog = dataStack.fetchOne(From<Dog>().where({ $0.master != me }))Declaration
Swift
public static func != (relationship: RelationshipContainer<O>.ToOne<D>, object: D?) -> Where<O> -
Creates a
Whereclause by checking if a sequence contains the value of a propertylet dog = dataStack.fetchOne(From<Dog>().where({ [john, joe, bob] ~= $0.master }))Declaration
Swift
public static func ~= <S>(sequence: S, relationship: RelationshipContainer<O>.ToOne<D>) -> Where<O> where D == S.Element, S : Sequence
-
Assigns an object to the relationship. The operation
dog.master .= personis equivalent to
dog.master.value = personDeclaration
Swift
public static func .= (relationship: RelationshipContainer<O>.ToOne<D>, newObject: D?) -
Assigns an object from another relationship. The operation
dog.master .= anotherDog.masteris equivalent to
dog.master.value = anotherDog.master.valueDeclaration
Swift
public static func .= <O2>(relationship: RelationshipContainer<O>.ToOne<D>, relationship2: RelationshipContainer<O2>.ToOne<D>) where O2 : CoreStoreObject -
Compares equality between a relationship’s object and another object
if dog.master .== person { ... }is equivalent to
if dog.master.value == person { ... }Declaration
Swift
public static func .== (relationship: RelationshipContainer<O>.ToOne<D>, object: D?) -> Bool -
Compares equality between an object and a relationship’s object
if dog.master .== person { ... }is equivalent to
if dog.master.value == person { ... }Declaration
Swift
public static func .== (object: D?, relationship: RelationshipContainer<O>.ToOne<D>) -> Bool -
Compares equality between a relationship’s object and another relationship’s object
if dog.master .== person { ... }is equivalent to
if dog.master.value == person { ... }Declaration
Swift
public static func .== <O2>(relationship: RelationshipContainer<O>.ToOne<D>, relationship2: RelationshipContainer<O2>.ToOne<D>) -> Bool where O2 : CoreStoreObject
View on GitHub
ToOne Class Reference