Skip to content
iOS swift tableview and collectionView Adapter
Branch: master
Clone or download
Latest commit 212c510 Jun 3, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example add header cell May 30, 2019
SNAdapter add header example header collection view May 30, 2019
images add paging example May 25, 2019
.gitignore Initial commit May 23, 2019
.travis.yml Initial commit May 23, 2019
LICENSE Initial commit May 23, 2019
README.md Update README.md Jun 3, 2019
SNAdapter.podspec add header cell May 30, 2019
_Pods.xcodeproj Initial commit May 23, 2019

README.md

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, ahmed.almasri@ymail.com

License

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

You can’t perform that action at this time.