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.
-
The
DynamicObject
type 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
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, ornil
if out of bounds -
Returns the object at the given
sectionIndex
anditemIndex
.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 returnnil
.itemIndex
the index for the object within the section. Using an
itemIndex
with an invalid range will returnnil
.Return Value
the
ObjectPublisher<O>
interfacing the object at the specified section and item index, ornil
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 anindexPath
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
, ornil
if out of bounds.Declaration
Swift
public subscript(safeIndexPath indexPath: IndexPath) -> ObjectPublisher<O>? { get }
Parameters
indexPath
the
IndexPath
for the object. Using anindexPath
with an invalid range will returnnil
.Return Value
the
ObjectPublisher<O>
interfacing the object at the specified index path, ornil
if out of bounds -
Checks if the
ListSnapshot
has at least one sectionDeclaration
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
orUITableViewDiffableDataSource
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 correspondingObjectPublisher
, or if you are using CoreStore’s built-inDiffableDataSource
s, 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 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 }
-
Parameters
itemID
the
ItemID
-
Returns an array of
SectionInfo
instances that contains a collection ofObjectPublisher<O>
items for each section.Declaration
Swift
public func sections() -> [SectionInfo]
-
Returns the
SectionInfo
that the specifiedItemID
belongs to, ornil
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 specifiedItemID
belongs to, ornil
if it is not in the list -
All object identifiers in the
ListSnapshot
Declaration
Swift
public var itemIDs: [ItemID] { get }
-
Returns an array of
ObjectPublisher
s for the items at the specified indicesDeclaration
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 -
Returns an array of
ObjectPublisher
s for the items in the specifiedSectionID
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 specifiedSectionID
-
Returns an array of
ObjectPublisher
s for the items in the specifiedSectionID
and indicesDeclaration
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 specifiedSectionID
and indices -
Returns a lazy sequence of
ObjectPublisher
s for the items at the specified indicesDeclaration
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 -
Returns a lazy sequence of
ObjectPublisher
s for the items in the specifiedSectionID
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 specifiedSectionID
-
Returns a lazy sequence of
ObjectPublisher
s for the items in the specifiedSectionID
and indicesDeclaration
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 specifiedSectionID
and indices
-
Appends extra items to the specified section
Declaration
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
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
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
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
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
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
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
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
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
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
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.
-
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 }