Latest 1.0.1
Homepage https://github.com/Aranoledur/FancySources
License MIT
Platforms ios 8.0
Authors

Flexible, generic and abstracted from UIKit data sources

Usage example

typealias DataSourceType = CollectionViewDataSource<SomeEntity>

func didLoadEntities(entities: [SomeEntity]) {        
    let dataSource = DataSourceType(items: entities)
    fill(with: dataSource)
}

func fill(with dataSource: DataSourceType) {
    dataSource.cellDescriptorCreator = {
        [weak self] item, index in

        if item.isGame {
            return CellDescriptor(nibName: String(describing: SomeGameCell.self), configure: {
                (cell: SomeGameCell) in

                cell.fill(with: item)
                cell.delegate = self
            })
        } else { //item.isChampionship
            return CellDescriptor(reuseIdentifier: String(describing: SomeChampionshipCell.self), configure: {
                (cell: SomeGameCell) in

                cell.setChampionship(item)
            })
        }
    }
    collectionView.dataSource = dataSource
    collectionView.reloadData()
}

Flexible

E.g. server told you to reload item with some ID. You can implement it like this

extension BaseViewDataSource where Item: SomeType {
    func update(_ newItem: Item) -> IndexPath {
        //find item with newItem.id, update it using new data and return IndexPath
    }
}

func didUpdateItem(_ updatedItem: Item) {
    let path = dataSource.update(updatedItem)
    view.updatePath(path)
}

And because this method implemented for a base class, all subclasses will have it too. So you don’t have to rewrite or copy/past it before switching from TableViewDataSource to CollectionViewDataSource or your own subclass. Even if you have 2-3 views in your project that shows same data, but in the different style, still you can use this method.

Generic

Interface for base class is class BaseViewDataSourceWithSections<Item, HeaderItem> {}, so you can put any data you want to this data sources. Even some wrappers or enums that can contains various data.

Abstracted from UIKit

No one is implementing UITableViewDelegate/UICollectionViewDelegate here. It’s up to you, so you can do it in your own way. Data sources only care about data, visual implementation is encapsulated to descriptorCreators. So when you deal with data source you don’t need to know how this data is displayed, you have to know only how items are structured. Visual part (cells) can be implemented by someone else, another class or another developer.

Easy to use

20 lines of code from usage example is the only thing you have to write to fill table or collection view.

Latest podspec

{
    "name": "FancySources",
    "version": "1.0.1",
    "summary": "Flexible, generic and abstracted from UIKit data sources.",
    "description": "FancySourcesnnFlexible, generic and abstracted from UIKit data sourcesnnUsage examplenntypealias DataSourceType = CollectionViewDataSourcennfunc didLoadEntities(entities: [SomeEntities]) {        n    let dataSource = DataSourceType(items: entities)n    fill(with: dataSource)n}nnfunc fill(with dataSource: DataSourceType) {n    dataSource.cellDescriptorCreator = {n        [weak self] item, index innn        return CellDescriptor(nibName: String(describing: SomeGameCell.self), configure: {n            (cell: SomeGameCell) innn            cell.fill(with: item)n            cell.delegate = selfn        })n    }n    collectionView.dataSource = dataSourcen    collectionView.reloadData()n}",
    "homepage": "https://github.com/Aranoledur/FancySources",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Nikolay Ischuk": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/Aranoledur/FancySources.git",
        "tag": "v1.0.1"
    },
    "source_files": [
        "FancySources",
        "FancySources/**/*.{h,m,swift}"
    ],
    "exclude_files": "FancySources/Exclude",
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4"
    }
}

Pin It on Pinterest

Share This