TableViewDiffableSection
public final class TableViewDiffableSection : GenericSectionUpdate<AnyHashable, String>
Represents changes proposed to a section Example
- Define a Cell Model
struct StringCellModel: Hashable {
let uniqueID: String
let text: String
// Defines uniqueness of the model
func hash(into hasher: inout Hasher) {
hasher.combine(uniqueID)
}
// Defines dynamic context of the model
static func == (lhs: Self, rhs: Self) -> Bool {
lhs.text == rhs.text
}
}
- Define a Cell
final class StringCell: UITableViewCell, ReusableCell, Configurable {
typealias Model = StringCellModel
func configure(with model: StringCellModel) {
textLabel?.text = "ID: \(model.uniqueID): \(model.text)"
selectionStyle = .none
}
}
- create a
TableViewRow
let model = StringCellModel(uniqueID: ID, text: title)
let row = TableViewRow<StringCell>(model: model,
onTap: { debugPrint("tapped with \($0)")})
// add rows if need
row.addRowLeadingActions(leadingActions)
row.addRowTrailingActions(trailingActions)
- Add the row to the cell
let updates = TableViewDiffableSection(id: "SectionID here")
updates.addRows([row])
- Create a ReusableView
final class TestReusableView: ReusableView, Configurable {
let label: UILabel
override init(reuseIdentifier: String?) {
// Init and Configure UILabel
super.init(reuseIdentifier: reuseIdentifier)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func configure(with txt: String) {
label.text = txt
}
}
- Create a header
let text = "My custom section"
let footer = ImmutableHeaderFooterProvider<TestReusableView>(model: text)
- Attach the header to a
TableViewDiffableSection
let updates = TableViewDiffableSection(id: "SectionID here")
updates.addHeader(header)
-
Undocumented
Declaration
Swift
public var settings: Settings
-
Example
- Define a Cell Model
struct StringCellModel: Hashable { let uniqueID: String let text: String // Defines uniqueness of the model func hash(into hasher: inout Hasher) { hasher.combine(uniqueID) } // Defines dynamic context of the model static func == (lhs: Self, rhs: Self) -> Bool { lhs.text == rhs.text } }
- Define a Cell
final class StringCell: UITableViewCell, ReusableCell, Configurable { typealias Model = StringCellModel func configure(with model: StringCellModel) { textLabel?.text = "ID: \(model.uniqueID): \(model.text)" selectionStyle = .none } }
- create a
TableViewRow
let model = StringCellModel(uniqueID: ID, text: title) let row = TableViewRow<StringCell>(model: model, onTap: { debugPrint("tapped with \($0)")}) // add rows if need row.addRowLeadingActions(leadingActions) row.addRowTrailingActions(trailingActions)
- Add the row to the cell
let updates = TableViewDiffableSection(id: "SectionID here") updates.addRows([row])
Declaration
Swift
public func addRows<Cell>(_ rows: [TableViewRow<Cell>]) where Cell : UITableViewCell, Cell : Configurable, Cell : Reusable, Cell.Model : Hashable
Parameters
rows
-
Method to add a header to the section
Usage Example
- Create a ReusableView
final class TestReusableView: ReusableView, Configurable { let label: UILabel override init(reuseIdentifier: String?) { // Init and Configure UILabel super.init(reuseIdentifier: reuseIdentifier) } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } func configure(with txt: String) { label.text = txt } }
- Create a header
let text = "My custom section" let footer = ImmutableHeaderFooterProvider<TestReusableView>(model: text)
- Attach the header to a
TableViewDiffableSection
let updates = TableViewDiffableSection(id: "SectionID here") updates.addHeader(header)
Declaration
Swift
public func addHeader<View>(_ header: HeaderFooterProvider<View>) where View : UITableViewHeaderFooterView, View : Configurable, View : Reusable
Parameters
header
-
Method to add a footer to the section
Usage Example
- Create a ReusableView
final class TestReusableView: ReusableView, Configurable { let label: UILabel override init(reuseIdentifier: String?) { // Init and Configure UILabel super.init(reuseIdentifier: reuseIdentifier) } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } func configure(with txt: String) { label.text = txt } }
- Create a header
let text = "My custom section" let footer = ImmutableHeaderFooterProvider<TestReusableView>(model: text)
- Attach the header to a
TableViewDiffableSection
let updates = TableViewDiffableSection(id: "SectionID here") updates.addHeader(footer)
Declaration
Swift
public func addFooter<View>(_ footer: HeaderFooterProvider<View>) where View : UITableViewHeaderFooterView, View : Configurable, View : Reusable
Parameters
footer
-
Undocumented
See moreDeclaration
Swift
public enum HeaderFooterUpdate
-
Provides settings for the sections like
- row animations
- section animations
- header view provider
- footer view provider
- flag is the section is collapsed
Declaration
Swift
public struct Settings