# ToManyOrdered

    public final class ToManyOrdered<D> : ToManyRelationshipKeyPathStringConvertible, RelationshipProtocol where D : CoreStoreObject

    extension RelationshipContainer.ToManyOrdered: RandomAccessCollection

The containing type for to-many ordered 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.ToManyOrdered<Dog>("pets", inverse: { $0.master })
    }

Important

`Relationship.ToManyOrdered` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties.

- `init(_:minCount:maxCount:deleteRule:versionHashModifier:renamingIdentifier:affectedByKeyPaths:)`

  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.ToManyOrdered<Dog>("pets", inverse: { $0.master })
      }

  #### Declaration

  Swift

      public convenience init(
          _ keyPath: KeyPathString,
          minCount: Int = 0,
          maxCount: Int = 0,
          deleteRule: DeleteRule = .nullify,
          versionHashModifier: @autoclosure @escaping () -> String? = nil,
          renamingIdentifier: @autoclosure @escaping () -> String? = nil,
          affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = [])

  #### Parameters

  `keyPath` | the permanent name for this relationship.
  `minCount` | the minimum number of objects in this relationship UNLESS THE RELATIONSHIP IS EMPTY. This means there might be zero objects in the relationship, which might be less than `minCount`. If the number of objects in the relationship do not satisfy `minCount` and `maxCount`, the transaction’s commit (or auto-commit) would fail with a validation error.
  `maxCount` | the maximum number of objects in this relationship. If the number of objects in the relationship do not satisfy `minCount` and `maxCount`, the transaction’s commit (or auto-commit) would fail with a validation error.
  `deleteRule` | defines what happens to relationship when an object is deleted. Valid values are `.nullify`, `.cascade`, and `.delete`. Defaults to `.nullify`.
  `versionHashModifier` | used 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.)
  `renamingIdentifier` | used 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.
  `affectedByKeyPaths` | a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.

- `init(_:minCount:maxCount:inverse:deleteRule:versionHashModifier:renamingIdentifier:affectedByKeyPaths:)`

  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.ToManyOrdered<Dog>("pets", inverse: { $0.master })
      }

  #### Declaration

  Swift

      public convenience init(
          _ keyPath: KeyPathString,
          minCount: Int = 0,
          maxCount: Int = 0,
          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

  `keyPath` | the permanent name for this relationship.
  `minCount` | the minimum number of objects in this relationship UNLESS THE RELATIONSHIP IS EMPTY. This means there might be zero objects in the relationship, which might be less than `minCount`. If the number of objects in the relationship do not satisfy `minCount` and `maxCount`, the transaction’s commit (or auto-commit) would fail with a validation error.
  `maxCount` | the maximum number of objects in this relationship. If the number of objects in the relationship do not satisfy `minCount` and `maxCount`, the transaction’s commit (or auto-commit) would fail with a validation error.
  `inverse` | the 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.
  `deleteRule` | defines what happens to relationship when an object is deleted. Valid values are `.nullify`, `.cascade`, and `.delete`. Defaults to `.nullify`.
  `versionHashModifier` | used 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.)
  `renamingIdentifier` | used 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.
  `affectedByKeyPaths` | a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.

- `init(_:minCount:maxCount:inverse:deleteRule:versionHashModifier:renamingIdentifier:affectedByKeyPaths:)`

  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.ToManyOrdered<Dog>("pets", inverse: { $0.master })
      }

  #### Declaration

  Swift

      public convenience init(
          _ keyPath: KeyPathString,
          minCount: Int = 0,
          maxCount: Int = 0,
          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

  `keyPath` | the permanent name for this relationship.
  `minCount` | the minimum number of objects in this relationship UNLESS THE RELATIONSHIP IS EMPTY. This means there might be zero objects in the relationship, which might be less than `minCount`. If the number of objects in the relationship do not satisfy `minCount` and `maxCount`, the transaction’s commit (or auto-commit) would fail with a validation error.
  `maxCount` | the maximum number of objects in this relationship. If the number of objects in the relationship do not satisfy `minCount` and `maxCount`, the transaction’s commit (or auto-commit) would fail with a validation error.
  `inverse` | the 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.
  `deleteRule` | defines what happens to relationship when an object is deleted. Valid values are `.nullify`, `.cascade`, and `.delete`. Defaults to `.nullify`.
  `versionHashModifier` | used 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.)
  `renamingIdentifier` | used 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.
  `affectedByKeyPaths` | a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.

- `init(_:minCount:maxCount:inverse:deleteRule:versionHashModifier:renamingIdentifier:affectedByKeyPaths:)`

  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.ToManyOrdered<Dog>("pets", inverse: { $0.master })
      }

  #### Declaration

  Swift

      public convenience init(
          _ keyPath: KeyPathString,
          minCount: Int = 0,
          maxCount: Int = 0,
          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

  `keyPath` | the permanent name for this relationship.
  `minCount` | the minimum number of objects in this relationship UNLESS THE RELATIONSHIP IS EMPTY. This means there might be zero objects in the relationship, which might be less than `minCount`. If the number of objects in the relationship do not satisfy `minCount` and `maxCount`, the transaction’s commit (or auto-commit) would fail with a validation error.
  `maxCount` | the maximum number of objects in this relationship. If the number of objects in the relationship do not satisfy `minCount` and `maxCount`, the transaction’s commit (or auto-commit) would fail with a validation error.
  `inverse` | the 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.
  `deleteRule` | defines what happens to relationship when an object is deleted. Valid values are `.nullify`, `.cascade`, and `.delete`. Defaults to `.nullify`.
  `versionHashModifier` | used 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.)
  `renamingIdentifier` | used 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.
  `affectedByKeyPaths` | a set of key paths for properties whose values affect the value of the receiver. This is similar to `NSManagedObject.keyPathsForValuesAffectingValue(forKey:)`.

- `value`

  The relationship value

  #### Declaration

  Swift

      public var value: ReturnValueType { get set }

### AnyKeyPathStringConvertible

- `cs_keyPathString`

  #### Declaration

  Swift

      public var cs_keyPathString: String { get }

### KeyPathStringConvertible

- `ObjectType`

  #### Declaration

  Swift

      public typealias ObjectType = O

- `DestinationValueType`

  #### Declaration

  Swift

      public typealias DestinationValueType = D

### RelationshipKeyPathStringConvertible

- `ReturnValueType`

  #### Declaration

  Swift

      public typealias ReturnValueType = [DestinationValueType]

### RelationshipContainer.ToManyOrdered

- `observe(options:changeHandler:)`

  Observes changes in the receiver value. When the returned `CoreStoreObjectKeyValueObservation` is deinited or invalidated, it will stop observing.

  #### Declaration

  Swift

      public func observe(options: NSKeyValueObservingOptions = [], changeHandler: @escaping (O, CoreStoreObjectOrderedDiff<D>) -> Void) -> CoreStoreObjectKeyValueObservation

  #### Parameters

  `options` | The flags indicating which values to include in the change dictionary.

### Sequence

- `Iterator`

  #### Declaration

  Swift

      public typealias Iterator = AnyIterator<D>

- `makeIterator()`

  #### Declaration

  Swift

      public func makeIterator() -> Iterator

### Collection

- `Index`

  #### Declaration

  Swift

      public typealias Index = Int

- `startIndex`

  #### Declaration

  Swift

      public var startIndex: Index { get }

- `endIndex`

  #### Declaration

  Swift

      public var endIndex: Index { get }

- `subscript(_:)`

  #### Declaration

  Swift

      public subscript(position: Index) -> Iterator.Element { get }

- `index(after:)`

  #### Declaration

  Swift

      public func index(after i: Index) -> Index

### Operations

- `.=(_:_:)`

  Assigns a sequence of objects to the relationship. The operation

      person.pets .= [dog, cat]

  is equivalent to

      person.pets.value = [dog, cat]

  #### Declaration

  Swift

      public static func .= <S>(relationship: RelationshipContainer<O>.ToManyOrdered<D>, newValue: S) where D == S.Element, S : Sequence

- `.=(_:_:)`

  Assigns a sequence of objects to the relationship. The operation

      person.pets .= anotherPerson.pets

  is equivalent to

      person.pets.value = anotherPerson.pets.value

  #### Declaration

  Swift

      public static func .= <O2>(relationship: RelationshipContainer<O>.ToManyOrdered<D>, relationship2: RelationshipContainer<O2>.ToManyOrdered<D>) where O2 : CoreStoreObject

- `.==(_:_:)`

  Compares equality between a relationship’s objects and a collection of objects

      if person.pets .== [dog, cat] { ... }

  is equivalent to

      if person.pets.value == [dog, cat] { ... }

  #### Declaration

  Swift

      public static func .== <C>(relationship: RelationshipContainer<O>.ToManyOrdered<D>, collection: C) -> Bool where D == C.Element, C : Collection

- `.==(_:_:)`

  Compares equality between a collection of objects and a relationship’s objects

      if [dog, cat] .== person.pets { ... }

  is equivalent to

      if [dog, cat] == person.pets.value { ... }

  #### Declaration

  Swift

      public static func .== <C>(collection: C, relationship: RelationshipContainer<O>.ToManyOrdered<D>) -> Bool where D == C.Element, C : Collection

- `.==(_:_:)`

  Compares equality between a relationship’s objects and a collection of objects

      if person.pets .== anotherPerson.pets { ... }

  is equivalent to

      if person.pets.value == anotherPerson.pets.value { ... }

  #### Declaration

  Swift

      public static func .== <O2>(relationship: RelationshipContainer<O>.ToManyOrdered<D>, relationship2: RelationshipContainer<O2>.ToManyOrdered<D>) -> Bool where O2 : CoreStoreObject