VladimirBorodko / Conventional

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conventional

platforms

Conventional is a library that helps you to:
  • unify storyboard segues and custom transitions
  • separate storyboard related code from view controllers
  • export transition logic without exposing view controllers
  • reduce boilerplate by using reflection in the way that is conventional for your project
  • have opportunity to deviate from convention where you need to
  • keep reuseable cell factories code expressive
  • combine cell registration and dequeueing code
  • detect internal inconsistency earlier in debug time
  • have debug information on what's wrong
  • catch objc / cpp exceptions in swift

Usage

Configure UITableView or UICollectionView:
override func viewDidLoad() {
  super.viewDidLoad()
  tableConfiguration = tableView.conventional.configuration
    .cell(StringCellV.self).byClass().configure(with: StringCellV.configure(stringVM:))
    .cell(IntCellV.self).inStoryboard().configure(with: IntCellV.configure(intVM:))
    .cellFromNib(ConventionalCell1V.self)
    .cellFromNib(ConventionalCell2V.self)
    .build()
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  return tableConfiguration.cell(from: tableView, at: indexPath, for: cellModels[indexPath.row])
}
Configure UIWindow:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  let window = UIWindow(frame: UIScreen.main.bounds)
  self.window = window

  windowConfiguration = window.conventional.configuration
    .register(WelcomeC.self).instantiateInitial().changeRoot().noContext()
    .build()

  windowConfiguration.transit(WelcomeC.self)
  return true
}
Configure UIViewController:
override func viewDidLoad() {
  super.viewDidLoad()
  configuration = conventional.configuration
    .embedd(SubController.self, \.subController)
    .showInitial(SeguedC.self)
    .build()
  viewModel = ViewModel(converter: configuration.converter, transit: {[weak self] in self?.configuration.perform($0)})
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  configuration.prepare(for: segue, sender: sender)
}

Requirements

  • Xcode 9.0
  • Swift 4.1

Dependencies

Conventional depends only on UIKit

About

License:MIT License


Languages

Language:Swift 96.3%Language:Objective-C++ 2.4%Language:Ruby 1.0%Language:Objective-C 0.4%