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.TableViewAdapters and DiffableDataSource.CollectionViewAdapters. 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 ObjectPublishers, 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)

  • The DynamicObject type associated with this list

    Declaration

    Swift

    public typealias ObjectType = O
  • The type for the section IDs

    Declaration

    Swift

    public typealias SectionID = String
  • The type for the item IDs

    Declaration

    Swift

    public typealias ItemID = O.ObjectID
  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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 DiffableDataSources, there is no need to inspect this property.

    Declaration

    Swift

    public var updatedItemIdentifiers: Set<NSManagedObjectID> { get }
  • The number of items in all sections in the ListSnapshot

    Declaration

    Swift

    public var numberOfItems: Int { get }
  • The number of sections in the ListSnapshot

    Declaration

    Swift

    public var numberOfSections: Int { get }
  • 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

  • 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

  • All section identifiers in the ListSnapshot

    Declaration

    Swift

    public var sectionIDs: [SectionID] { get }
  • 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

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

    Declaration

    Swift

    public func sections() -> [SectionInfo]
  • 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

  • All object identifiers in the ListSnapshot

    Declaration

    Swift

    public var itemIDs: [ItemID] { get }
  • 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

  • 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

  • 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

  • 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

  • Returns an array of ObjectPublishers 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 ObjectPublishers for the items at the specified indices

  • Returns an array of ObjectPublishers 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 ObjectPublishers for the items in the specified SectionID

  • Returns an array of ObjectPublishers 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 ObjectPublishers for the items in the specified SectionID and indices

  • Returns a lazy sequence of ObjectPublishers 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 ObjectPublishers for the items at the specified indices

  • Returns a lazy sequence of ObjectPublishers 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 ObjectPublishers for the items in the specified SectionID

  • Returns a lazy sequence of ObjectPublishers 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 ObjectPublishers for the items in the specified SectionID and indices

Public (Mutators)

  • 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

  • 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.

  • 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.

  • 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.

  • 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.

  • 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

  • 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.

  • Deletes all items

    Declaration

    Swift

    public mutating func deleteAllItems()
  • 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.

  • 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.

  • 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.

  • 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

  • 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.

  • 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

  • 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.

  • 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.

  • 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.

  • 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

  • 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.

  • 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.

  • 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.

  • 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.

  • 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

  • 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

BidirectionalCollection

Sequence

Equatable

  • Declaration

    Swift

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

Hashable

  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)

CustomDebugStringConvertible

  • Declaration

    Swift

    public var debugDescription: String { get }