Latest 1.0
Homepage https://github.com/wleii/Section
License MIT
Platforms ios 9.0
Authors

Section Build Status Carthage compatible Version License Platform

Section is a very lightweight Swfit Framework that uses POP (Protocol-Oriented-Programming) to help you build any list views

Usage

extension AwesomeViewController: ReuseSectionable, UITableViewDelegate, UITableViewDataSource {
    var viewModels: [ViewModel] {
        return [awesomeModels]
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return sn.numberOfSections(in: tableView)
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return sn.tableView(tableView, numberOfRowsInSection: section)
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return sn.tableView(tableView, cellForRowAt: indexPath)
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return sn.tableView(tableView, heightForRowAt: indexPath)
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if let awesomeModel = sn.viewModel(at: indexPath) as? AwesomeModel {
            // Do someting here
    }
    }
}

private struct AwesomeModel: ViewModel {
    let title: String

    var viewSize: ViewSize {
        return ViewSize.schemeSize({ (containerSize) -> CGSize in
            return CGSize(width: containerSize.width, height: 44)
        })
    }
    var viewType: ViewType.Type {
        return AwesomeCell.self
    }
}

private class AwesomeCell: UITableViewCell, ViewType {
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)   
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    func didSet(viewModel: ViewModel) {
        textLabel?.text = (viewModel as? AwesomeModel)?.title
    }
}

Installation

Cocoapods

Section is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'Section'

Carthage

For Carthage, add the following to your Cartfile:

github "wleii/Section"

Author

Lei Wang, [email protected]

License

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

Latest podspec

{
    "name": "Section",
    "version": "1.0",
    "summary": "Section, It's help you very easy to build an extensible list.",
    "description": "Section, It's help you very easy to build an extensible list.",
    "homepage": "https://github.com/wleii/Section",
    "license": "MIT",
    "authors": {
        "Lei Wang": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/wleii/Section.git",
        "tag": "1.0"
    },
    "source_files": "Section",
    "exclude_files": "Classes/Exclude",
    "xcconfig": {
        "SWIFT_VERSION": "4.0"
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This