Skip to content

Data sources for table and collection views in a more reusable manner

License

Notifications You must be signed in to change notification settings

DavidObfuscator/GenericDataSource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GenericDataSource

Data sources for table and collection views in a more reusable manner

Installation

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

To install GenericDataSource with Carthage, add the following line to your Cartfile.

github "DavidObfuscator/GenericDataSource" "master"

Run carthage update to build the framework and drag the built GenericDataSource.framework into your Xcode project.

Basic Usage

Create view model:

struct PetViewModel {
    let name: String
    let numberOfLegs: Int
}

Create cell view:

class PetTableViewCell: UITableViewCell, ModelBoundedCell {
    typealias SupportedModel = PetViewModel

    func configure(model: PetViewModel) {
        // configure cell with view model
    }
}

Set up table view:

class PetListViewController: UIViewController {
    private let tableViewDataSource = TableViewDataSource<PetTableViewCell>()
    private lazy var tableView: UITableView = {
        let tableView = UITableView(frame: CGRect.zero, style: .grouped)
        tableView.register(PetTableViewCell.self)
        tableView.dataSource = tableViewDataSource
        return tableView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        // add tableview ...

        // Set up ur data:
        tableViewDataSource.setData(data:
            [
                PetViewModel(name: "Doggy", numberOfLegs: 4),
                PetViewModel(name: "Chicky", numberOfLegs: 2),
            ]
        )
        tableView.reloadData()
    }
}

License

MIT license. See the LICENSE file for details.

About

Data sources for table and collection views in a more reusable manner

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published