Chainable 1.0.0

Chainable 1.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2017
SPMSupports SPM

Maintained by xiaoyaogaojian.



Chainable 1.0.0

  • By
  • xiaoyaogaojian

Chainable

CI Status
Version
License
Platform

A simple syntax sugar for UIKit.

Example

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

Requirements

swift 4.x

Installation

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

pod 'Chainable'

Usage

UIView

Vanilla

let label = UILabel()

label.text = "😂"
label.textColor = .red

view.addSubview(label)

NSLayoutConstraint.activate([
  label.centerXAnchor.constraint(equalTo: view.centerXAnchor),
  label.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])

With Chainable

UILabel().chain
  .config {
    $0.text = "😄"
    $0.textColor = .green
  }
  .add(toSuperView: view)
  .layout {
    [
      $0.centerXAnchor.constraint(equalTo: view.centerXAnchor),
      $0.centerYAnchor.constraint(equalTo: view.centerYAnchor)
    ]
  }

You can also use SnapKit to make constraints, just replace layout with snp_layout.

.snp_layout {
  $.center.equalToSuperview()
}

UIViewController

Vanilla

let alertController = UIAlertController(title: "Title", message: "Some message", preferredStyle: .alert)

alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel))
alertController.addAction(UIAlertAction(title: "OK", style: .default) { _ in
  print("OK")
})

present(alertController, animated: true)

With Chainable

UIAlertController(title: "Title", message: "Some message", preferredStyle: .alert).chain
  .config {
    $0.addAction(UIAlertAction(title: "Cancel", style: .cancel))
    $0.addAction(UIAlertAction(title: "OK", style: .default) { _ in
      print("OK")
    })
  }
  .presented(by: self)

Author

xiaoyaogaojian, [email protected]

License

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