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.
-
The
DynamicObjecttype associated with this listDeclaration
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
indexthe 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
nilif out of bounds.Declaration
Swift
public subscript(safeIndex index: Index) -> ObjectPublisher<O>? { get }Parameters
indexthe 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, ornilif out of bounds -
Returns the object at the given
sectionIndexanditemIndex.Declaration
Swift
public subscript( sectionIndex: Int, itemIndex: Int ) -> ObjectPublisher<O>Parameters
sectionIndexthe section index for the object. Using a
sectionIndexwith an invalid range will raise an exception.itemIndexthe index for the object within the section. Using an
itemIndexwith 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
nilif out of bounds.Declaration
Swift
public subscript( safeSectionIndex sectionIndex: Int, safeItemIndex itemIndex: Int ) -> ObjectPublisher<O>?Parameters
sectionIndexthe section index for the object. Using a
sectionIndexwith an invalid range will returnnil.itemIndexthe index for the object within the section. Using an
itemIndexwith an invalid range will returnnil.Return Value
the
ObjectPublisher<O>interfacing the object at the specified section and item index, ornilif out of bounds -
Returns the object at the given
IndexPath.Declaration
Swift
public subscript(indexPath: IndexPath) -> ObjectPublisher<O> { get }Parameters
indexPaththe
IndexPathfor the object. Using anindexPathwith 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, ornilif out of bounds.Declaration
Swift
public subscript(safeIndexPath indexPath: IndexPath) -> ObjectPublisher<O>? { get }Parameters
indexPaththe
IndexPathfor the object. Using anindexPathwith an invalid range will returnnil.Return Value
the
ObjectPublisher<O>interfacing the object at the specified index path, ornilif out of bounds -
Checks if the
ListSnapshothas at least one sectionDeclaration
Swift
public func hasSections() -> BoolReturn Value
trueif at least one section exists,falseotherwise -
Checks if the
ListSnapshothas at least one object in any section.Declaration
Swift
public func hasItems() -> BoolReturn Value
trueif at least one object in any section exists,falseotherwise -
Checks if the
ListSnapshothas at least one object in the specified section.Declaration
Swift
public func hasItems(inSectionIndex sectionIndex: Int) -> BoolParameters
sectionIndexthe section index. Using an index outside the valid range will return
false.Return Value
trueif at least one object in the specified section exists,falseotherwise -
Checks if the
ListSnapshothas at least one object the specified section.Declaration
Swift
public func hasItems(inSectionWithID sectionID: SectionID) -> BoolParameters
sectionIDthe section identifier. Using an index outside the valid range will return
false.Return Value
trueif at least one object in the specified section exists,falseotherwise -
Returns item identifiers for updated objects. This is mainly useful for Data Source adapters such as
UICollectionViewDiffableDataSourceorUITableViewDiffableDataSourcewhich 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 correspondingObjectPublisher, or if you are using CoreStore’s built-inDiffableDataSources, 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
ListSnapshotDeclaration
Swift
public var numberOfItems: Int { get } -
The number of sections in the
ListSnapshotDeclaration
Swift
public var numberOfSections: Int { get } -
Returns the number of items at the specified section index.
Declaration
Swift
public func numberOfItems(inSectionIndex sectionIndex: Int) -> IntParameters
sectionIndexthe 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
ListSnapshotDeclaration
Swift
public var sectionIDs: [SectionID] { get } -
Parameters
itemIDthe
ItemID -
Returns an array of
SectionInfoinstances that contains a collection ofObjectPublisher<O>items for each section.Declaration
Swift
public func sections() -> [SectionInfo] -
Returns the
SectionInfothat the specifiedItemIDbelongs to, ornilif it is not in the list.Declaration
Swift
public func section(containingItemWithID itemID: ItemID) -> SectionInfo?Parameters
itemIDthe
ItemIDReturn Value
the
SectionInfothat the specifiedItemIDbelongs to, ornilif it is not in the list -
All object identifiers in the
ListSnapshotDeclaration
Swift
public var itemIDs: [ItemID] { get } -
Returns an array of
ObjectPublishers for the items at the specified indicesDeclaration
Swift
public func items<S>(atIndices indices: S) -> [ObjectPublisher<O>] where S : Sequence, S.Element == IntParameters
indicesthe 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 specifiedSectionIDDeclaration
Swift
public func items(inSectionWithID sectionID: SectionID) -> [ObjectPublisher<O>]Parameters
sectionIDthe
SectionID. Specifying an invalid value will raise an exception.Return Value
an array of
ObjectPublishers for the items in the specifiedSectionID -
Returns an array of
ObjectPublishers for the items in the specifiedSectionIDand indicesDeclaration
Swift
public func items<S: Sequence>( inSectionWithID sectionID: SectionID, atIndices itemIndices: S ) -> [ObjectPublisher<O>] where S.Element == IntParameters
sectionIDthe
SectionID. Specifying an invalid value will raise an exception.itemIndicesthe 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 specifiedSectionIDand indices -
Returns a lazy sequence of
ObjectPublishers for the items at the specified indicesDeclaration
Swift
public func lazy<S>(atIndices indices: S) -> LazyMapSequence<S, ObjectPublisher<O>> where S : Sequence, S.Element == IntParameters
indicesthe 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 specifiedSectionIDDeclaration
Swift
public func lazy(inSectionWithID sectionID: SectionID) -> LazyMapSequence<[NSManagedObjectID], ObjectPublisher<O>>Parameters
sectionIDthe
SectionID. Specifying an invalid value will raise an exception.Return Value
a lazy sequence of
ObjectPublishers for the items in the specifiedSectionID -
Returns a lazy sequence of
ObjectPublishers for the items in the specifiedSectionIDand indicesDeclaration
Swift
public func lazy<S: Sequence>( inSectionWithID sectionID: SectionID, atIndices itemIndices: S ) -> LazyMapSequence<S, ObjectPublisher<O>> where S.Element == IntParameters
sectionIDthe
SectionID. Specifying an invalid value will raise an exception.itemIndicesthe 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 specifiedSectionIDand indices
-
Appends extra items to the specified section
Declaration
Parameters
itemIDsthe object identifiers for the objects to append
sectionIDthe section to append the items to
-
Appends extra items to the specified section index
Declaration
Parameters
itemIDsthe object identifiers for the objects to append
sectionIndexthe section index to append the items to. Specifying an invalid value will raise an exception.
-
Inserts extra items before a specified item
Declaration
Parameters
itemIDsthe object identifiers for the objects to insert
beforeItemIDan existing identifier to insert items before of. Specifying an invalid value will raise an exception.
-
Inserts extra items after a specified item
Declaration
Parameters
itemIDsthe object identifiers for the objects to insert
beforeItemIDan existing identifier to insert items after of. Specifying an invalid value will raise an exception.
-
Inserts extra items at a specified index path
Declaration
Parameters
itemIDsthe object identifiers for the objects to insert
indexPathan 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 == NSManagedObjectIDParameters
itemIDsthe 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 == IndexPathParameters
itemIndexPathsthe 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
Parameters
itemIDan object identifier in the list to move. Specifying an invalid value will raise an exception.
beforeItemIDanother identifier to move the item before of. Specifying an invalid value will raise an exception.
-
Moves an item after another specified item
Parameters
itemIDan object identifier in the list to move. Specifying an invalid value will raise an exception.
beforeItemIDanother 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
itemIndexPathan index path in the list to move. Specifying an invalid value will raise an exception.
newIndexPaththe 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 == NSManagedObjectIDParameters
itemIDsthe 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 == IndexPathParameters
itemIndexPathsthe 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 == StringParameters
sectionIDsthe sections to append
-
Inserts new sections before an existing section
Declaration
Parameters
sectionIDsthe section identifiers for the sections to insert
beforeSectionIDan existing identifier to insert items before of. Specifying an invalid value will raise an exception.
-
Inserts new sections after an existing section
Declaration
Parameters
sectionIDsthe section identifiers for the sections to insert
beforeSectionIDan 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 == StringParameters
sectionIDsthe section identifiers for the sections to insert
sectionIndexan 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 == StringParameters
sectionIDsthe 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 == IntParameters
sectionIndicesthe section indices to delete. Specifying an invalid value will raise an exception.
-
Moves a section before another specified section
Declaration
Parameters
sectionIDa section identifier in the list to move. Specifying an invalid value will raise an exception.
beforeSectionIDanother identifier to move the section before of. Specifying an invalid value will raise an exception.
-
Moves a section after another specified section
Declaration
Parameters
sectionIDa section identifier in the list to move. Specifying an invalid value will raise an exception.
afterSectionIDanother 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
sectionIndexa section index in the list to move. Specifying an invalid value will raise an exception.
newSectionIndexthe 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 == StringParameters
sectionIDsthe 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 == IntParameters
sectionIndicesthe section indices to reload. Specifying an invalid value will raise an exception.
-
Declaration
Swift
public typealias Element = ObjectPublisher<O> -
Declaration
Swift
public typealias Index = Int
-
Declaration
Swift
public static func == (lhs: `Self`, rhs: `Self`) -> Bool
-
Declaration
Swift
public func hash(into hasher: inout Hasher)
-
Declaration
Swift
public var debugDescription: String { get }
View on GitHub
ListSnapshot Structure Reference