CollectionViewModel
public struct CollectionViewModel : DiffableViewModel
extension CollectionViewModel: Collection, RandomAccessCollection
extension CollectionViewModel: CustomDebugStringConvertible
Represents a collection view with sections and items.
-
Returns the empty collection view model.
Declaration
Swift
public static var empty: `Self` { get }
-
A unique id for this model.
Declaration
Swift
public let id: UniqueIdentifier
-
The sections in the collection.
Declaration
Swift
public let sections: [SectionViewModel]
-
Initializes a new
CollectionViewModel
.Declaration
Swift
public init(id: UniqueIdentifier, sections: [SectionViewModel] = [])
Parameters
id
A unique identifier for the collection.
sections
The sections in the collection.
-
Returns the section for the specified
id
.Declaration
Swift
public func sectionViewModel(for id: UniqueIdentifier) -> SectionViewModel?
Parameters
id
The identifier for the section.
Return Value
The section, if it exists.
-
Returns the section at the specified index.
Precondition
The specified
index
must be valid.Declaration
Swift
public func sectionViewModel(at index: Int) -> SectionViewModel
Parameters
index
The index of the section.
Return Value
The section at
index
.
-
Returns the cell for the specified
id
.Declaration
Swift
public func cellViewModel(for id: UniqueIdentifier) -> AnyCellViewModel?
Parameters
id
The identifier for the cell.
Return Value
The cell, if it exists.
-
Returns the cell at the specified index path.
Precondition
The specified
indexPath
must be valid.Declaration
Swift
public func cellViewModel(at indexPath: IndexPath) -> AnyCellViewModel
Parameters
indexPath
The index path of the cell.
Return Value
The cell at
indexPath
.
-
Returns the supplementary view for the specified
id
.Declaration
Swift
public func supplementaryViewModel(for id: UniqueIdentifier) -> AnySupplementaryViewModel?
Parameters
id
The identifier for the supplementary view.
Return Value
The supplementary view, if it exists.
-
Returns the supplementary view for the specified kind and index path.
Precondition
The specified
indexPath
must be valid.Declaration
Swift
public func supplementaryViewModel(ofKind kind: String, at indexPath: IndexPath) -> AnySupplementaryViewModel?
Parameters
kind
The kind of the supplementary view.
indexPath
The index path for the view.
Return Value
The supplementary view.
-
Returns the cell at the specified index path.
Precondition
The specified
indexPath
must be valid.Declaration
Swift
public subscript(indexPath: IndexPath) -> AnyCellViewModel { get }
Parameters
indexPath
The index path of the cell.
Return Value
The cell at
indexPath
. -
Returns the cell at the specified indexes.
Precondition
The specified indexes must be valid.
Declaration
Swift
public subscript(item item: Int, section section: Int) -> AnyCellViewModel { get }
Parameters
item
The item index of the cell.
section
The section index of the cell.
Return Value
The cell at
item
andsection
.