Giter Club home page Giter Club logo

snadapter's Introduction

A declarative type-safe framework for building fast and flexible lists with TableView & CollectionView, No more delegates and datasource. Just a fully type-safe declarative content approach

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Using

Step 1: Import the SNAdapter module in swift.

import SNAdapter

TableView

Step 1: declare a new class or struct conform from SNCellableModel

struct MyModel: SNCellableModel {

  let title: String
}

Step 2: declare a new UITableViewCell conform from SNCellable

class MyCell: UITableViewCell, SNCellable {

  func configure(_ object: SNCellableModel?) {
    guard let myModel = object as? MyModel else { return }

    self.textLabel?.text = myModel.title
  }

}

Step 3: Take a reference to SNTableViewSection and SNTableViewAdapter into your controller.

 private var mySection: SNTableViewSection<MyModel, MyCell>!
 private var myAdapter: SNTableViewAdapter!

Step 4: Initialize the SNTableViewSection and SNTableViewAdapter in your viewDidLoad .

override func viewDidLoad() {
  super.viewDidLoad()
  ///....
  
  // MARK: - call setup section

  setupMySection()
  
  ///...
}

private func setupMySection() {

 mySection = SNTableViewSection<MyModel, MyCell>(items: getMyListData())
 myAdapter = SNTableViewAdapter(sections: [mySection])
 myTableView.setAdapter(myAdapter)
 
}

private func getMyListData() -> [MyModel] {

return [MyModel(title: "Item 1"), MyModel(title: "Item 2")]

}

More Example

CollectionView

Step 1: declare new UICollectionViewCell inherent form SNCellable

class MyCell: UICollectionViewCell, SNCellable {

 @IBOutlet weak var titleLabel: UILabel!
 
func configure(_ object: SNCellableModel?) {
guard let myModel = object as? MyModel else { return }

  titleLabel.text = myModel.title
}

}

Step 2: Take a reference to SNCollectionViewSection and SNCollectionViewAdapter into your controller.

private var mySection: SNCollectionViewSection<MyModel, MyCell>!
private var myAdapter: SNCollectionViewAdapter!

Step 3: Initialize the SNCollectionViewSection and SNCollectionViewAdapter in your viewDidLoad .

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

// MARK: - call setup section

setupMySection()

///...
}

private func setupMySection() {

mySection = SNCollectionViewSection<MyModel, MyCell>(items: getMyListData())
myAdapter = SNCollectionViewAdapter(sections: [mySection])
myCollectionView.setAdapter(myAdapter)

}

private func getMyListData() -> [MyModel] {

return [MyModel(title: "Item 1"), MyModel(title: "Item 2")]

}

More Example

Requirements

  • Swift 4.2+
  • Xcode 10.0+
  • iOS 11.0+

Installation

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

pod 'SNAdapter'

Author

ahmedAlmasri, [email protected]

License

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

snadapter's People

Contributors

ahmedalmasri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.