Swiftpack.co - Package - Swift-Gurus/EZSource

EZSource

Build Status License Platform

Documentation

Usage

The core of EZSource for UITableView. Provides declarative API to work with UITableView All you need is to initialize the source, create rows, add them to section updates and call update function The rest is handled by EZSource, next time you have to update the UITableView, EZSource will find take care about inserting, deleting or reloading rows using animation provided in the section updates

Usage 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 Data Source
let config = DiffableTableViewDataSource.Config(tableView: tableView,
                                                cellTypes: [StringCell.self],
                                                headerFooters: [TestReusableView.self])
source = DiffableTableViewDataSource(config: config)
  • 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)
  • Call updates on the source
source.update(sections: [updates])

Documentaion

For more information check the documentaion page

Author

Swift Gurus., alexei.hmelevski@gmail.com

License

EZSource is available under the MIT license. See the LICENSE file for more info.

Github

link
Stars: 2

Used By

Total: 0

Releases

Added mutability to row - 2020-02-27 20:31:47

SwipeConfiguration for Leading and Trailing - 2020-02-19 19:16:08

Long Swipe Support for Rows - 2020-02-18 20:26:12

added dynamic sections - 2019-08-13 17:55:10

Remove deletable sections - 2019-07-08 13:51:09

Deletable Section - 2019-07-02 19:20:35

Swift 5 files fixes - 2019-05-13 19:23:23

Fixes - 2019-05-13 19:14:31

Swift 5 Fixes - 2019-05-13 19:10:46

Swift 5 Migration - 2019-05-13 17:59:37

Multiple Selection Fix - 2019-03-22 14:37:31

Multiple Selection - 2018-11-21 03:24:35

Gemfile update - 2018-11-06 15:48:36

Api updates - 2018-11-01 18:48:11

Changing Update with animation - 2018-08-13 18:06:32

Crashfix - 2018-07-19 14:56:35

fixing a crash when section are collapsed

Crash fix - 2018-07-06 14:44:51

Added Swifty Collection for safety - 2018-06-12 21:07:59

First Commit - 2018-06-12 02:37:01