DiffableDataSourceSnapshot
public struct DiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType> where SectionIdentifierType : Hashable, ItemIdentifierType : Hashable
A class for backporting NSDiffableDataSourceSnapshot
introduced in iOS 13.0+, macOS 10.15+, tvOS 13.0+.
Represents the mutable state of diffable data source of UI.
-
Creates a new empty snapshot object.
Declaration
Swift
public init()
-
The number of item identifiers in the snapshot.
Declaration
Swift
public var numberOfItems: Int { get }
-
The number of section identifiers in the snapshot.
Declaration
Swift
public var numberOfSections: Int { get }
-
All section identifiers in the snapshot.
Declaration
Swift
public var sectionIdentifiers: [SectionIdentifierType] { get }
-
All item identifiers in the snapshot.
Declaration
Swift
public var itemIdentifiers: [ItemIdentifierType] { get }
-
Returns the number of item identifiers in the specified section.
Declaration
Swift
public func numberOfItems(inSection identifier: SectionIdentifierType) -> Int
Parameters
identifier
An identifier of section.
Return Value
The number of item identifiers in the specified section.
-
Returns the item identifiers in the specified section.
Declaration
Swift
public func itemIdentifiers(inSection identifier: SectionIdentifierType) -> [ItemIdentifierType]
Parameters
identifier
An identifier of section.
Return Value
The item identifiers in the specified section.
-
Returns a section identifier containing the specified item.
Declaration
Swift
public func sectionIdentifier(containingItem identifier: ItemIdentifierType) -> SectionIdentifierType?
Parameters
identifier
An identifier of item.
Return Value
A section identifier containing the specified item.
-
Returns an index of the specified item.
Declaration
Swift
public func indexOfItem(_ identifier: ItemIdentifierType) -> Int?
Parameters
identifier
An identifier of item.
Return Value
An index of the specified item.
-
Returns an index of the specified section.
Declaration
Swift
public func indexOfSection(_ identifier: SectionIdentifierType) -> Int?
Parameters
identifier
An identifier of section.
Return Value
An index of the specified section.
-
Appends the given item identifiers to the specified section or last section.
Declaration
Swift
public mutating func appendItems(_ identifiers: [ItemIdentifierType], toSection sectionIdentifier: SectionIdentifierType? = nil)
Parameters
identifiers
The item identifiers to be appended.
sectionIdentifier
An identifier of section to append the given identiciers.
-
Inserts the given item identifiers before the specified item.
Declaration
Swift
public mutating func insertItems(_ identifiers: [ItemIdentifierType], beforeItem beforeIdentifier: ItemIdentifierType)
Parameters
identifiers
The item identifiers to be inserted.
beforeIdentifier
An identifier of item.
-
Inserts the given item identifiers after the specified item.
Declaration
Swift
public mutating func insertItems(_ identifiers: [ItemIdentifierType], afterItem afterIdentifier: ItemIdentifierType)
Parameters
identifiers
The item identifiers to be inserted.
afterIdentifier
An identifier of item.
-
Deletes the specified items.
Declaration
Swift
public mutating func deleteItems(_ identifiers: [ItemIdentifierType])
Parameters
identifiers
The item identifiers to be deleted.
-
Deletes the all items in the snapshot.
Declaration
Swift
public mutating func deleteAllItems()
-
Moves the given item identifier before the specified item.
Declaration
Swift
public mutating func moveItem(_ identifier: ItemIdentifierType, beforeItem toIdentifier: ItemIdentifierType)
Parameters
identifier
An item identifier to be moved.
toIdentifier
An identifier of item.
-
Moves the given item identifier after the specified item.
Declaration
Swift
public mutating func moveItem(_ identifier: ItemIdentifierType, afterItem toIdentifier: ItemIdentifierType)
Parameters
identifier
An item identifier to be moved.
toIdentifier
An identifier of item.
-
Reloads the specified items.
Declaration
Swift
public mutating func reloadItems(_ identifiers: [ItemIdentifierType])
Parameters
identifiers
The item identifiers to be reloaded.
-
Appends the given section identifiers to the end of sections.
Declaration
Swift
public mutating func appendSections(_ identifiers: [SectionIdentifierType])
Parameters
identifiers
The section identifiers to be appended.
-
Inserts the given section identifiers before the specified section.
Declaration
Swift
public mutating func insertSections(_ identifiers: [SectionIdentifierType], beforeSection toIdentifier: SectionIdentifierType)
Parameters
identifiers
The section identifiers to be inserted.
toIdentifier
An identifier of setion.
-
Inserts the given section identifiers after the specified section.
Declaration
Swift
public mutating func insertSections(_ identifiers: [SectionIdentifierType], afterSection toIdentifier: SectionIdentifierType)
Parameters
identifiers
The section identifiers to be inserted.
toIdentifier
An identifier of setion.
-
Deletes the specified sections.
Declaration
Swift
public mutating func deleteSections(_ identifiers: [SectionIdentifierType])
Parameters
identifiers
The section identifiers to be deleted.
-
Moves the given section identifier before the specified section.
Declaration
Swift
public mutating func moveSection(_ identifier: SectionIdentifierType, beforeSection toIdentifier: SectionIdentifierType)
Parameters
identifier
A section identifier to be moved.
toIdentifier
An identifier of section.
-
Moves the given section identifier after the specified section.
Declaration
Swift
public mutating func moveSection(_ identifier: SectionIdentifierType, afterSection toIdentifier: SectionIdentifierType)
Parameters
identifier
A section identifier to be moved.
toIdentifier
An identifier of section.
-
Reloads the specified sections.
Declaration
Swift
public mutating func reloadSections(_ identifiers: [SectionIdentifierType])
Parameters
identifiers
The section identifiers to be reloaded.