DynamicSectionTexts
public final class DynamicSectionTexts : SectionTexts
Generates section texts by fetching the first element of a section and transforms it with a given closure into section texts.
Example
//A data provider with multiple sections. Each section contains trains from a single type
let dataProvider: ArrayDataProvider<Train> = //
//Use type name as a section header and shortname as a section index title.
let sectionTitleProvider = DynamicSectionTexts(dataProvider: dataProvider,
sectionTextWithElement: { train, _ in return train.type.name },
using: .firstElementInSection)
-
Creates a
DynamicSectionTexts
.Declaration
Swift
public init<D: DataProvider>(dataProvider: D, sectionTextWithDataProvider: @escaping (D, Int) -> String?)
Parameters
dataProvider
the data provider used as source for header titles.
sectionTextWithDataProvider
a closure to transform a data provider and a given section index into an optional
String
, which is used as a section text. -
Creates a
DynamicHeaderTitlesProvider
.Declaration
Swift
public convenience init<D: DataProvider>(dataProvider: D, sectionTextWithElement: @escaping (D.Element, IndexPath) -> String?, using element: SectionMetaData.SectionMetaDataElement)
Parameters
dataProvider
the data provider used as source for header titles.
sectionTextWithElement
a closure to transform an Element which is part of the data provider into a single
String
, which is used as a section text. -
Generates a optional section title for a given section
Declaration
Swift
public func text(inSection section: Int) -> String?
Parameters
section
the section to generate the title for
Return Value
a section header title