Skip to content

Commit dbfd212

Browse files
committed
give CollectionViewModel an id for debugging
1 parent 165e056 commit dbfd212

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Sources/CollectionViewModel.swift

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import Foundation
1515
import UIKit
1616

1717
/// Represents a collection view with sections and items.
18-
public struct CollectionViewModel: Hashable {
18+
public struct CollectionViewModel: Hashable, DiffableViewModel {
19+
// MARK: DiffableViewModel
20+
21+
public var id: UniqueIdentifier
22+
1923
// MARK: Properties
2024

2125
public let sections: [SectionViewModel]
@@ -41,7 +45,8 @@ public struct CollectionViewModel: Hashable {
4145

4246
// MARK: Init
4347

44-
public init(sections: [SectionViewModel]) {
48+
public init(id: UniqueIdentifier = UUID(), sections: [SectionViewModel]) {
49+
self.id = id
4550
self.sections = sections.filter { !$0.isEmpty }
4651
}
4752

@@ -130,7 +135,7 @@ extension CollectionViewModel: Collection, RandomAccessCollection {
130135
extension CollectionViewModel: CustomDebugStringConvertible {
131136
/// :nodoc:
132137
public var debugDescription: String {
133-
var text = "<CollectionViewModel:\n sections:\n"
138+
var text = "<CollectionViewModel:\n id: \(self.id)\n sections:\n"
134139

135140
for sectionIndex in 0..<self.count {
136141
let section = self[sectionIndex]

0 commit comments

Comments
 (0)