Skip to content

shalkovy/SwiftyDataSource

 
 

Repository files navigation

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) { }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 98.8%
  • Other 1.2%