diff --git a/Sources/DiffableDataSourceSnapshot.swift b/Sources/DiffableDataSourceSnapshot.swift index c57a575..8d0ead1 100644 --- a/Sources/DiffableDataSourceSnapshot.swift +++ b/Sources/DiffableDataSourceSnapshot.swift @@ -8,12 +8,16 @@ public struct DiffableDataSourceSnapshot Int { - return itemIdentifiers(inSection: identifier).count + return structure.numberOfItems(in: identifier) } /// Returns the item identifiers in the specified section. diff --git a/Sources/Internal/SnapshotStructure.swift b/Sources/Internal/SnapshotStructure.swift index 35bcc67..89e08d9 100644 --- a/Sources/Internal/SnapshotStructure.swift +++ b/Sources/Internal/SnapshotStructure.swift @@ -56,6 +56,14 @@ struct SnapshotStructure { .map { $0.differenceIdentifier } } + func numberOfItems(in sectionID: SectionID, file: StaticString = #file, line: UInt = #line) -> Int { + guard let sectionIndex = sectionIndex(of: sectionID) else { + specifiedSectionIsNotFound(sectionID, file: file, line: line) + } + + return sections[sectionIndex].elements.count + } + func items(in sectionID: SectionID, file: StaticString = #file, line: UInt = #line) -> [ItemID] { guard let sectionIndex = sectionIndex(of: sectionID) else { specifiedSectionIsNotFound(sectionID, file: file, line: line)