CollectionDataProvider

open class CollectionDataProvider<ItemType>

Class representing Data to be used in a collection view.

This class manages a two dimensional array of an associated item type. The first dimension of the array serves as an indicator of the section while the second dimension are the items in the section.

  • A two dimensional array of the generic item type.

    Declaration

    Swift

    open var items: [[ItemType]]
  • The index path of the last item. This value is nil if items is empty.

    Declaration

    Swift

    open var lastIndexPath: IndexPath? { get }
  • Returns a newly initialized collection data provider with the specified two dimensional array of an item type.

    Declaration

    Swift

    public convenience init(items: [[ItemType]])

    Parameters

    items

    A two dimensional array of an item type.

    Return Value

    The initialized collection data provider.

  • Returns a newly initialized collection data provided with the specified array of an item type. The given array will be put into another array to be identified as a two dimensional array.

    Declaration

    Swift

    public convenience init(sectionItems: [ItemType])

    Parameters

    items

    An array of an item type.

    Return Value

    The initialized collection data provider.

  • Returns the number of sections contained in the items array.

    Declaration

    Swift

    open func numberOfSections() -> Int

    Return Value

    An Int value representing the number of sections.

  • Returns the number of items for the specified section contained in the items array.

    Declaration

    Swift

    open func numberOfItems(in section: Int) -> Int

    Parameters

    section

    The section to get the number of items.

    Return Value

    An Int value representing the number of items in the specified section. If section is out of bounds, this returns zero.

  • Returns the item for the specified index path contained in the items array.

    Declaration

    Swift

    open func item(at indexPath: IndexPath) -> ItemType?

    Parameters

    indexPath

    The IndexPath of the item.

    Return Value

    An optional value with the generic item type. The optional value is nil if the index path is out of bounds

  • Returns items for the specified section contained in the items array.

    Declaration

    Swift

    open func items(atSection section: Int) -> [ItemType]

    Parameters

    section

    The section of the items.

    Return Value

    An array of the generic item type. The array will be empty if the section is out of bounds.

  • Adds an item to the items array. The added item will be appended in the last section.

    Declaration

    Swift

    @discardableResult
    open func add(_ item: ItemType) -> IndexPath

    Parameters

    item

    An object of the generic item type.

    Return Value

    The IndexPath of the added item.

  • Adds items to the items array. The added items will be appended in the last section.

    Declaration

    Swift

    @discardableResult
    open func add(_ items: [ItemType]) -> [IndexPath]

    Parameters

    items

    An array of the generic item type.

    Return Value

    An array of IndexPaths of the added items.

  • Updates an item in the items array.

    If index path is out of bounds, this does nothing.

    Declaration

    Swift

    open func updateItem(at indexPath: IndexPath, value: ItemType)

    Parameters

    indexPath

    The IndexPath of the item to update.

    value

    The updated object of the generic item type.

  • Removes an item in the items array.

    If index path is out of bounds, this does nothing.

    Declaration

    Swift

    open func remove(at indexPath: IndexPath)

    Parameters

    indexPath

    The IndexPath of the item to remove.

  • Removes all items in the items array.

    Declaration

    Swift

    open func removeAllItems()