Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Sources/DiffableDataSourceSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ public struct DiffableDataSourceSnapshot<SectionIdentifierType: Hashable, ItemId

/// The number of item identifiers in the snapshot.
public var numberOfItems: Int {
return itemIdentifiers.count
var count = 0
for section in structure.sections {
count += numberOfItems(inSection: section.differenceIdentifier)
}
return count
}

/// The number of section identifiers in the snapshot.
public var numberOfSections: Int {
return sectionIdentifiers.count
return structure.sections.count
}

/// All section identifiers in the snapshot.
Expand All @@ -33,7 +37,7 @@ public struct DiffableDataSourceSnapshot<SectionIdentifierType: Hashable, ItemId
///
/// - Returns: The number of item identifiers in the specified section.
public func numberOfItems(inSection identifier: SectionIdentifierType) -> Int {
return itemIdentifiers(inSection: identifier).count
return structure.numberOfItems(in: identifier)
}

/// Returns the item identifiers in the specified section.
Expand Down
8 changes: 8 additions & 0 deletions Sources/Internal/SnapshotStructure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ struct SnapshotStructure<SectionID: Hashable, ItemID: Hashable> {
.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)
Expand Down