Swiftpack.co - Package - abakhtin/SwiftyDataSource

SwiftyDataSource

there are two main abstractions in library:

  1. Container helps work with information and can handle data
  2. Data Source abstraction, which include container and displays data from container

Containers

  1. ArrayDataSourceContainer

used with arrays data

func insert(object: ResultType, at indexPath: IndexPath) throws { }
func remove(at indexPath: IndexPath) throws { }
func replace(object: ResultType, at indexPath: IndexPath, reloadAction: Bool = false) throws { }
func removeAll() { }
  1. FRCDataSourceContainer

used with data from fetch result controller

var fetchedObjects: [ResultType]
func object(at indexPath: IndexPath) -> ResultType? { }
func search(_ block:(IndexPath, ResultType) -> Bool) { }
func indexPath(for object: ResultType) -> IndexPath? { }
  1. FilterableDataSourceContainer

func filterData(by searchText: String?) { }
func numberOfItems(in section: Int) -> Int? { }
func object(at indexPath: IndexPath) -> T? { }

DataSources

  1. CollectionViewDataSource (use with CollectionViewDataSourceDelegate)

  2. TableViewDataSource (use with TableViewDataSourceDelegate)

func dataSource(_ dataSource: DataSourceProtocol, cellIdentifierFor object: ObjectType, at indexPath: IndexPath) -> String?
func dataSource(_ dataSource: DataSourceProtocol, accessoryTypeFor object: ObjectType, at indexPath: IndexPath) -> UITableViewCell.AccessoryType?
func dataSource(_ dataSource: DataSourceProtocol, didSelect object: ObjectType, at indexPath: IndexPath)
func dataSource(_ dataSource: DataSourceProtocol, didDeselect object: ObjectType, at indexPath: IndexPath?)
  1. MapViewDataSource (use with MapViewDataSourceDelegate)

func dataSource(_ dataSource: DataSourceProtocol, didSelect object: ObjectType) { }

all DataSources have property noDataView which is show, when there are no data in containers

code example with FRCDataSourceContainer and tableView

View Controller properties

var container: FRCDataSourceContainer<ClassType>?

@IBOutlet weak var tableView: UITableView! {
didSet {
    dataSource.tableView = tableView
    tableView.registerCellNibForDefaultIdentifier(TableViewCell.self)
    dataSource.noDataView = NoDataView()
}

private lazy var dataSource: TableViewDataSource<ClassType> = {
    let dataSource = TableViewDataSource<ClassType>(delegate: AnyTableViewDataSourceDelegate(self))
    dataSource.cellIdentifier = TableViewCell.defaultReuseIdentifier
    return dataSource
}()

View Controller methods

extension ViewController: TableViewDataSourceDelegate {
    typealias ObjectType = ClassType
    func dataSource(_ dataSource: DataSourceProtocol, didSelect object: ClassType, at indexPath: IndexPath) { }
}

Github

link
Stars: 0

Dependencies

Used By

Total: 0

Releases

1.0.67 - 2020-07-09 12:04:35

- 2020-05-05 11:32:17