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
idA unique identifier for the collection.
sectionsThe sections in the collection.
-
Returns the section for the specified
id.Declaration
Swift
public func sectionViewModel(for id: UniqueIdentifier) -> SectionViewModel?Parameters
idThe identifier for the section.
Return Value
The section, if it exists.
-
Returns the section at the specified index.
Precondition
The specified
indexmust be valid.Declaration
Swift
public func sectionViewModel(at index: Int) -> SectionViewModelParameters
indexThe 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
idThe identifier for the cell.
Return Value
The cell, if it exists.
-
Returns the cell at the specified index path.
Precondition
The specified
indexPathmust be valid.Declaration
Swift
public func cellViewModel(at indexPath: IndexPath) -> AnyCellViewModelParameters
indexPathThe 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
idThe 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
indexPathmust be valid.Declaration
Swift
public func supplementaryViewModel(ofKind kind: String, at indexPath: IndexPath) -> AnySupplementaryViewModel?Parameters
kindThe kind of the supplementary view.
indexPathThe index path for the view.
Return Value
The supplementary view.
-
Returns the cell at the specified index path.
Precondition
The specified
indexPathmust be valid.Declaration
Swift
public subscript(indexPath: IndexPath) -> AnyCellViewModel { get }Parameters
indexPathThe 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
itemThe item index of the cell.
sectionThe section index of the cell.
Return Value
The cell at
itemandsection.
View on GitHub