Latest 1.0.0
Homepage https://github.com/xiaoyaogaojian/Chainable
License MIT
Platforms ios 8.0
Dependencies SnapKit
Authors

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 {
  $0.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.

Latest podspec

{
    "name": "Chainable",
    "version": "1.0.0",
    "summary": "Chainable syntax sugar for UIKit",
    "description": "Just a simple syntax sugar for UIKit to write chainable code.",
    "homepage": "https://github.com/xiaoyaogaojian/Chainable",
    "authors": {
        "xiaoyaogaojian": "[email protected]"
    },
    "source": {
        "git": "https://github.com/xiaoyaogaojian/Chainable.git",
        "tag": "1.0.0"
    },
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Chainable/Classes/**/*",
    "dependencies": {
        "SnapKit": []
    },
    "subspecs": [
        {
            "name": "Core",
            "source_files": "Chainable/Classes/Core/**/*"
        },
        {
            "name": "SnapKit",
            "source_files": "Chainable/Classes/SnapKit/**/*",
            "dependencies": {
                "Chainable/Core": [],
                "SnapKit": []
            }
        }
    ]
}

Pin It on Pinterest

Share This