# ListSnapshot

    public struct ListSnapshot<O> : RandomAccessCollection, Hashable where O : DynamicObject

    extension ListSnapshot: CustomDebugStringConvertible, CoreStoreDebugStringConvertible

A `ListSnapshot` holds a stable list of `DynamicObject` identifiers. This is typically created by a `ListPublisher` and are designed to work well with `DiffableDataSource.TableViewAdapter`s and `DiffableDataSource.CollectionViewAdapter`s. For detailed examples, see the documentation on `DiffableDataSource.TableViewAdapter` and `DiffableDataSource.CollectionViewAdapter`.

While the `ListSnapshot` stores only object identifiers, all accessors to its items return `ObjectPublisher`s, which are lazily created. For more details, see the documentation on `ListObject`.

Since `ListSnapshot` is a value type, you can freely modify its items.

### Public (Accessors)

- `ObjectType`

  The `DynamicObject` type associated with this list

  #### Declaration

  Swift

      public typealias ObjectType = O

- `SectionID`

  The type for the section IDs

  #### Declaration

  Swift

      public typealias SectionID = String

- `ItemID`

  The type for the item IDs

  #### Declaration

  Swift

      public typealias ItemID = O.ObjectID

- `subscript(_:)`

  Returns the object at the given index.

  #### Declaration

  Swift

      public subscript(index: Index) -> ObjectPublisher<O> { get }

  #### Parameters

  `index` | the index of the object. Using an index above the valid range will raise an exception.

  #### Return Value

  the `ObjectPublisher<O>` interfacing the object at the specified index

- `subscript(safeIndex:)`

  Returns the object at the given index, or `nil` if out of bounds.

  #### Declaration

  Swift

      public subscript(safeIndex index: Index) -> ObjectPublisher<O>? { get }

  #### Parameters

  `index` | the index for the object. Using an index above the valid range will return `nil`.

  #### Return Value

  the `ObjectPublisher<O>` interfacing the object at the specified index, or `nil` if out of bounds

- `subscript(_:_:)`

  Returns the object at the given `sectionIndex` and `itemIndex`.

  #### Declaration

  Swift

      public subscript(
          sectionIndex: Int,
          itemIndex: Int
      ) -> ObjectPublisher<O>

  #### Parameters

  `sectionIndex` | the section index for the object. Using a `sectionIndex` with an invalid range will raise an exception.
  `itemIndex` | the index for the object within the section. Using an `itemIndex` with an invalid range will raise an exception.

  #### Return Value

  the `ObjectPublisher<O>` interfacing the object at the specified section and item index

- `subscript(safeSectionIndex:safeItemIndex:)`

  Returns the object at the given section and item index, or `nil` if out of bounds.

  #### Declaration

  Swift

      public subscript(
          safeSectionIndex sectionIndex: Int,
          safeItemIndex itemIndex: Int
      ) -> ObjectPublisher<O>?

  #### Parameters

  `sectionIndex` | the section index for the object. Using a `sectionIndex` with an invalid range will return `nil`.
  `itemIndex` | the index for the object within the section. Using an `itemIndex` with an invalid range will return `nil`.

  #### Return Value

  the `ObjectPublisher<O>` interfacing the object at the specified section and item index, or `nil` if out of bounds

- `subscript(_:)`

  Returns the object at the given `IndexPath`.

  #### Declaration

  Swift

      public subscript(indexPath: IndexPath) -> ObjectPublisher<O> { get }

  #### Parameters

  `indexPath` | the `IndexPath` for the object. Using an `indexPath` with an invalid range will raise an exception.

  #### Return Value

  the `ObjectPublisher<O>` interfacing the object at the specified index path

- `subscript(safeIndexPath:)`

  Returns the object at the given `IndexPath`, or `nil` if out of bounds.

  #### Declaration

  Swift

      public subscript(safeIndexPath indexPath: IndexPath) -> ObjectPublisher<O>? { get }

  #### Parameters

  `indexPath` | the `IndexPath` for the object. Using an `indexPath` with an invalid range will return `nil`.

  #### Return Value

  the `ObjectPublisher<O>` interfacing the object at the specified index path, or `nil` if out of bounds

- `hasSections()`

  Checks if the `ListSnapshot` has at least one section

  #### Declaration

  Swift

      public func hasSections() -> Bool

  #### Return Value

  `true` if at least one section exists, `false` otherwise

- `hasItems()`

  Checks if the `ListSnapshot` has at least one object in any section.

  #### Declaration

  Swift

      public func hasItems() -> Bool

  #### Return Value

  `true` if at least one object in any section exists, `false` otherwise

- `hasItems(inSectionIndex:)`

  Checks if the `ListSnapshot` has at least one object in the specified section.

  #### Declaration

  Swift

      public func hasItems(inSectionIndex sectionIndex: Int) -> Bool

  #### Parameters

  `sectionIndex` | the section index. Using an index outside the valid range will return `false`.

  #### Return Value

  `true` if at least one object in the specified section exists, `false` otherwise

- `hasItems(inSectionWithID:)`

  Checks if the `ListSnapshot` has at least one object the specified section.

  #### Declaration

  Swift

      public func hasItems(inSectionWithID sectionID: SectionID) -> Bool

  #### Parameters

  `sectionID` | the section identifier. Using an index outside the valid range will return `false`.

  #### Return Value

  `true` if at least one object in the specified section exists, `false` otherwise

- `updatedItemIdentifiers`

  Returns item identifiers for updated objects. This is mainly useful for Data Source adapters such as `UICollectionViewDiffableDataSource` or `UITableViewDiffableDataSource` which work on collection diffs when reloading. Since objects with same IDs resolve as “equal” in their old and new states, adapters may need extra heuristics to determine which row items need reloading. If your row items are all observing changes from each corresponding `ObjectPublisher`, or if you are using CoreStore’s built-in `DiffableDataSource`s, there is no need to inspect this property.

  #### Declaration

  Swift

      public var updatedItemIdentifiers: Set<NSManagedObjectID> { get }

- `numberOfItems`

  The number of items in all sections in the `ListSnapshot`

  #### Declaration

  Swift

      public var numberOfItems: Int { get }

- `numberOfSections`

  The number of sections in the `ListSnapshot`

  #### Declaration

  Swift

      public var numberOfSections: Int { get }

- `numberOfItems(inSectionWithID:)`

  Returns the number of items for the specified `SectionID`.

  #### Declaration

  Swift

      public func numberOfItems(inSectionWithID sectionID: SectionID) -> Int

  #### Parameters

  `sectionID` | the `SectionID`. Specifying an invalid value will raise an exception.

  #### Return Value

  The number of items in the given `SectionID`

- `numberOfItems(inSectionIndex:)`

  Returns the number of items at the specified section index.

  #### Declaration

  Swift

      public func numberOfItems(inSectionIndex sectionIndex: Int) -> Int

  #### Parameters

  `sectionIndex` | the index of the section. Specifying an invalid value will raise an exception.

  #### Return Value

  The number of items in the given `SectionID`

- `sectionIDs`

  All section identifiers in the `ListSnapshot`

  #### Declaration

  Swift

      public var sectionIDs: [SectionID] { get }

- `sectionID(containingItemWithID:)`

  Returns the `SectionID` that the specified `ItemID` belongs to, or `nil` if it is not in the list.

  #### Declaration

  Swift

      public func sectionID(containingItemWithID itemID: ItemID) -> SectionID?

  #### Parameters

  `itemID` | the `ItemID`

  #### Return Value

  the `SectionID` that the specified `ItemID` belongs to, or `nil` if it is not in the list

- `sections()`

  Returns an array of `SectionInfo` instances that contains a collection of `ObjectPublisher<O>` items for each section.

  #### Declaration

  Swift

      public func sections() -> [SectionInfo]

- `section(containingItemWithID:)`

  Returns the `SectionInfo` that the specified `ItemID` belongs to, or `nil` if it is not in the list.

  #### Declaration

  Swift

      public func section(containingItemWithID itemID: ItemID) -> SectionInfo?

  #### Parameters

  `itemID` | the `ItemID`

  #### Return Value

  the `SectionInfo` that the specified `ItemID` belongs to, or `nil` if it is not in the list

- `itemIDs`

  All object identifiers in the `ListSnapshot`

  #### Declaration

  Swift

      public var itemIDs: [ItemID] { get }

- `itemIDs(inSectionWithID:)`

  Returns the item identifiers belonging to the specified `SectionID`.

  #### Declaration

  Swift

      public func itemIDs(inSectionWithID sectionID: SectionID) -> [ItemID]

  #### Parameters

  `sectionID` | the `SectionID`. Specifying an invalid value will raise an exception.

  #### Return Value

  the `ItemID` array belonging to the given `SectionID`

- `itemIDs(inSectionWithID:atIndices:)`

  Returns the item identifiers belonging to the specified `SectionID` and a `Sequence` of item indices.

  #### Declaration

  Swift

      public func itemIDs<S: Sequence>(
          inSectionWithID sectionID: SectionID,
          atIndices indices: S
      ) -> [ItemID] where S.Element == Int

  #### Parameters

  `sectionID` | the `SectionID`. Specifying an invalid value will raise an exception.
  `indices` | the positions of the itemIDs to return. Specifying an invalid value will raise an exception.

  #### Return Value

  the `ItemID` array belonging to the given `SectionID` at the specified indices

- `indexOfItem(withID:)`

  Returns the index of the specified `ItemID` in the whole list, or `nil` if it is not in the list.

  #### Declaration

  Swift

      public func indexOfItem(withID itemID: ItemID) -> Index?

  #### Parameters

  `itemID` | the `ItemID`

  #### Return Value

  the index of the specified `ItemID`, or `nil` if it is not in the list

- `indexOfSection(withID:)`

  Returns the index of the specified `SectionID`, or `nil` if it is not in the list.

  #### Declaration

  Swift

      public func indexOfSection(withID sectionID: SectionID) -> Int?

  #### Parameters

  `sectionID` | the `SectionID`

  #### Return Value

  the index of the specified `SectionID`, or `nil` if it is not in the list

- `items(atIndices:)`

  Returns an array of `ObjectPublisher`s for the items at the specified indices

  #### Declaration

  Swift

      public func items<S>(atIndices indices: S) -> [ObjectPublisher<O>] where S : Sequence, S.Element == Int

  #### Parameters

  `indices` | the positions of items. Specifying an invalid value will raise an exception.

  #### Return Value

  an array of `ObjectPublisher`s for the items at the specified indices

- `items(inSectionWithID:)`

  Returns an array of `ObjectPublisher`s for the items in the specified `SectionID`

  #### Declaration

  Swift

      public func items(inSectionWithID sectionID: SectionID) -> [ObjectPublisher<O>]

  #### Parameters

  `sectionID` | the `SectionID`. Specifying an invalid value will raise an exception.

  #### Return Value

  an array of `ObjectPublisher`s for the items in the specified `SectionID`

- `items(inSectionWithID:atIndices:)`

  Returns an array of `ObjectPublisher`s for the items in the specified `SectionID` and indices

  #### Declaration

  Swift

      public func items<S: Sequence>(
          inSectionWithID sectionID: SectionID,
          atIndices itemIndices: S
      ) -> [ObjectPublisher<O>] where S.Element == Int

  #### Parameters

  `sectionID` | the `SectionID`. Specifying an invalid value will raise an exception.
  `itemIndices` | the positions of items within the section. Specifying an invalid value will raise an exception.

  #### Return Value

  an array of `ObjectPublisher`s for the items in the specified `SectionID` and indices

- `lazy(atIndices:)`

  Returns a lazy sequence of `ObjectPublisher`s for the items at the specified indices

  #### Declaration

  Swift

      public func lazy<S>(atIndices indices: S) -> LazyMapSequence<S, ObjectPublisher<O>> where S : Sequence, S.Element == Int

  #### Parameters

  `indices` | the positions of items. Specifying an invalid value will raise an exception.

  #### Return Value

  a lazy sequence of `ObjectPublisher`s for the items at the specified indices

- `lazy(inSectionWithID:)`

  Returns a lazy sequence of `ObjectPublisher`s for the items in the specified `SectionID`

  #### Declaration

  Swift

      public func lazy(inSectionWithID sectionID: SectionID) -> LazyMapSequence<[NSManagedObjectID], ObjectPublisher<O>>

  #### Parameters

  `sectionID` | the `SectionID`. Specifying an invalid value will raise an exception.

  #### Return Value

  a lazy sequence of `ObjectPublisher`s for the items in the specified `SectionID`

- `lazy(inSectionWithID:atIndices:)`

  Returns a lazy sequence of `ObjectPublisher`s for the items in the specified `SectionID` and indices

  #### Declaration

  Swift

      public func lazy<S: Sequence>(
          inSectionWithID sectionID: SectionID,
          atIndices itemIndices: S
      ) -> LazyMapSequence<S, ObjectPublisher<O>> where S.Element == Int

  #### Parameters

  `sectionID` | the `SectionID`. Specifying an invalid value will raise an exception.
  `itemIndices` | the positions of items within the section. Specifying an invalid value will raise an exception.

  #### Return Value

  a lazy sequence of `ObjectPublisher`s for the items in the specified `SectionID` and indices

### Public (Mutators)

- `appendItems(withIDs:toSectionWithID:)`

  Appends extra items to the specified section

  #### Declaration

  Swift

      public mutating func appendItems<C: Collection>(
          withIDs itemIDs: C,
          toSectionWithID sectionID: SectionID? = nil
      ) where C.Element == ItemID

  #### Parameters

  `itemIDs` | the object identifiers for the objects to append
  `sectionID` | the section to append the items to

- `appendItems(with:toSectionAt:)`

  Appends extra items to the specified section index

  #### Declaration

  Swift

      public mutating func appendItems<C: Collection>(
          with itemIDs: C,
          toSectionAt sectionIndex: Int
      ) where C.Element == ItemID

  #### Parameters

  `itemIDs` | the object identifiers for the objects to append
  `sectionIndex` | the section index to append the items to. Specifying an invalid value will raise an exception.

- `insertItems(withIDs:beforeItemID:)`

  Inserts extra items before a specified item

  #### Declaration

  Swift

      public mutating func insertItems<C: Collection>(
          withIDs itemIDs: C,
          beforeItemID: ItemID
      ) where C.Element == ItemID

  #### Parameters

  `itemIDs` | the object identifiers for the objects to insert
  `beforeItemID` | an existing identifier to insert items before of. Specifying an invalid value will raise an exception.

- `insertItems(withIDs:afterItemID:)`

  Inserts extra items after a specified item

  #### Declaration

  Swift

      public mutating func insertItems<C: Collection>(
          withIDs itemIDs: C,
          afterItemID: ItemID
      ) where C.Element == ItemID

  #### Parameters

  `itemIDs` | the object identifiers for the objects to insert
  `beforeItemID` | an existing identifier to insert items after of. Specifying an invalid value will raise an exception.

- `insertItems(withIDs:at:)`

  Inserts extra items at a specified index path

  #### Declaration

  Swift

      public mutating func insertItems<C: Collection>(
          withIDs itemIDs: C,
          at indexPath: IndexPath
      ) where C.Element == ItemID

  #### Parameters

  `itemIDs` | the object identifiers for the objects to insert
  `indexPath` | an indexPath to insert the items into. Specifying an invalid value will raise an exception.

- `deleteItems(withIDs:)`

  Deletes the specified items

  #### Declaration

  Swift

      public mutating func deleteItems<C>(withIDs itemIDs: C) where C : Collection, C.Element == NSManagedObjectID

  #### Parameters

  `itemIDs` | the object identifiers for the objects to delete

- `deleteItems(at:)`

  Deletes the items at the specified index paths

  #### Declaration

  Swift

      public mutating func deleteItems<C>(at itemIndexPaths: C) where C : Collection, C.Element == IndexPath

  #### Parameters

  `itemIndexPaths` | the index paths for the objects to delete. Specifying an invalid value will raise an exception.

- `deleteAllItems()`

  Deletes all items

  #### Declaration

  Swift

      public mutating func deleteAllItems()

- `moveItem(withID:beforeItemID:)`

  Moves an item before another specified item

  #### Declaration

  Swift

      public mutating func moveItem(
          withID itemID: ItemID,
          beforeItemID: ItemID
      )

  #### Parameters

  `itemID` | an object identifier in the list to move. Specifying an invalid value will raise an exception.
  `beforeItemID` | another identifier to move the item before of. Specifying an invalid value will raise an exception.

- `moveItem(withID:afterItemID:)`

  Moves an item after another specified item

  #### Declaration

  Swift

      public mutating func moveItem(
          withID itemID: ItemID,
          afterItemID: ItemID
      )

  #### Parameters

  `itemID` | an object identifier in the list to move. Specifying an invalid value will raise an exception.
  `beforeItemID` | another identifier to move the item after of. Specifying an invalid value will raise an exception.

- `moveItem(at:to:)`

  Moves an item at an index path to a new index path

  #### Declaration

  Swift

      public mutating func moveItem(
          at itemIndexPath: IndexPath,
          to newIndexPath: IndexPath
      )

  #### Parameters

  `itemIndexPath` | an index path in the list to move. Specifying an invalid value will raise an exception.
  `newIndexPath` | the new index path to move the item into. Specifying an invalid value will raise an exception.

- `reloadItems(withIDs:)`

  Marks the specified items as reloaded

  #### Declaration

  Swift

      public mutating func reloadItems<C>(withIDs itemIDs: C) where C : Collection, C.Element == NSManagedObjectID

  #### Parameters

  `itemIDs` | the object identifiers to reload

- `reloadItems(at:)`

  Marks the specified index paths as reloaded

  #### Declaration

  Swift

      public mutating func reloadItems<C>(at itemIndexPaths: C) where C : Collection, C.Element == IndexPath

  #### Parameters

  `itemIndexPaths` | the index paths to reload. Specifying an invalid value will raise an exception.

- `appendSections(withIDs:)`

  Appends new section identifiers to the end of the list

  #### Declaration

  Swift

      public mutating func appendSections<C>(withIDs sectionIDs: C) where C : Collection, C.Element == String

  #### Parameters

  `sectionIDs` | the sections to append

- `insertSections(withIDs:beforeSectionID:)`

  Inserts new sections before an existing section

  #### Declaration

  Swift

      public mutating func insertSections<C: Collection>(
          withIDs sectionIDs: C,
          beforeSectionID: SectionID
      ) where C.Element == SectionID

  #### Parameters

  `sectionIDs` | the section identifiers for the sections to insert
  `beforeSectionID` | an existing identifier to insert items before of. Specifying an invalid value will raise an exception.

- `insertSections(withIDs:afterSectionID:)`

  Inserts new sections after an existing section

  #### Declaration

  Swift

      public mutating func insertSections<C: Collection>(
          withIDs sectionIDs: C,
          afterSectionID: SectionID
      ) where C.Element == SectionID

  #### Parameters

  `sectionIDs` | the section identifiers for the sections to insert
  `beforeSectionID` | an existing identifier to insert items after of. Specifying an invalid value will raise an exception.

- `insertSections(_:at:)`

  Inserts new sections into an existing section index

  #### Declaration

  Swift

      public mutating func insertSections<C: Collection>(
          _ sectionIDs: C,
          at sectionIndex: Int
      ) where C.Element == String

  #### Parameters

  `sectionIDs` | the section identifiers for the sections to insert
  `sectionIndex` | an existing section index to insert items into. Specifying an invalid value will raise an exception.

- `deleteSections(withIDs:)`

  Deletes the specified sections

  #### Declaration

  Swift

      public mutating func deleteSections<C>(withIDs sectionIDs: C) where C : Collection, C.Element == String

  #### Parameters

  `sectionIDs` | the section identifiers for the sections to delete

- `deleteSections(at:)`

  Deletes the specified section indices

  #### Declaration

  Swift

      public mutating func deleteSections<C>(at sectionIndices: C) where C : Collection, C.Element == Int

  #### Parameters

  `sectionIndices` | the section indices to delete. Specifying an invalid value will raise an exception.

- `moveSection(withID:beforeSectionID:)`

  Moves a section before another specified section

  #### Declaration

  Swift

      public mutating func moveSection(
          withID sectionID: SectionID,
          beforeSectionID: SectionID
      )

  #### Parameters

  `sectionID` | a section identifier in the list to move. Specifying an invalid value will raise an exception.
  `beforeSectionID` | another identifier to move the section before of. Specifying an invalid value will raise an exception.

- `moveSection(withID:afterSectionID:)`

  Moves a section after another specified section

  #### Declaration

  Swift

      public mutating func moveSection(
          withID sectionID: SectionID,
          afterSectionID: SectionID
      )

  #### Parameters

  `sectionID` | a section identifier in the list to move. Specifying an invalid value will raise an exception.
  `afterSectionID` | another identifier to move the section after of. Specifying an invalid value will raise an exception.

- `moveSection(at:to:)`

  Moves a section at a specified index to a new index

  #### Declaration

  Swift

      public mutating func moveSection(
          at sectionIndex: Int,
          to newSectionIndex: Int
      )

  #### Parameters

  `sectionIndex` | a section index in the list to move. Specifying an invalid value will raise an exception.
  `newSectionIndex` | the new section index to move into. Specifying an invalid value will raise an exception.

- `reloadSections(withIDs:)`

  Marks the specified sections as reloaded

  #### Declaration

  Swift

      public mutating func reloadSections<C>(withIDs sectionIDs: C) where C : Collection, C.Element == String

  #### Parameters

  `sectionIDs` | the section identifiers to reload

- `reloadSections(at:)`

  Marks the specified section indices as reloaded

  #### Declaration

  Swift

      public mutating func reloadSections<C>(at sectionIndices: C) where C : Collection, C.Element == Int

  #### Parameters

  `sectionIndices` | the section indices to reload. Specifying an invalid value will raise an exception.

### RandomAccessCollection

- `startIndex`

  #### Declaration

  Swift

      public var startIndex: Index { get }

- `endIndex`

  #### Declaration

  Swift

      public var endIndex: Index { get }

- `index(after:)`

  #### Declaration

  Swift

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

- `formIndex(after:)`

  #### Declaration

  Swift

      public func formIndex(after i: inout Index)

- `index(before:)`

  #### Declaration

  Swift

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

- `formIndex(before:)`

  #### Declaration

  Swift

      public func formIndex(before i: inout Index)

### BidirectionalCollection

- `index(_:offsetBy:)`

  #### Declaration

  Swift

      public func index(_ i: Index, offsetBy distance: Int) -> Index

- `index(_:offsetBy:limitedBy:)`

  #### Declaration

  Swift

      public func index(_ i: Index, offsetBy distance: Int, limitedBy limit: Int) -> Index?

- `distance(from:to:)`

  #### Declaration

  Swift

      public func distance(from start: Index, to end: Index) -> Int

- `subscript(_:)`

  #### Declaration

  Swift

      public subscript(bounds: Range<Index>) -> ArraySlice<Element> { get }

### Sequence

- `Element`

  #### Declaration

  Swift

      public typealias Element = ObjectPublisher<O>

- `Index`

  #### Declaration

  Swift

      public typealias Index = Int

### Equatable

- `==(_:_:)`

  #### Declaration

  Swift

      public static func == (lhs: `Self`, rhs: `Self`) -> Bool

### Hashable

- `hash(into:)`

  #### Declaration

  Swift

      public func hash(into hasher: inout Hasher)

### CustomDebugStringConvertible

- `debugDescription`

  #### Declaration

  Swift

      public var debugDescription: String { get }