Alacrity 0.5.4

Alacrity 0.5.4

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Mar 2019
SPMSupports SPM

Maintained by Julio Alorro.



Alacrity 0.5.4

  • By
  • Julio Alorro

Alacrity

Alacrity is a library that brings a fluent interface for UIView and its subclasses.

CI Status Version License Platform

Example

When writing UI code programmatically we would typically write code such as this:

class YourCustomView: UIView {
    let aView: UIView = UIView()
    let aLabel: UILabel = UILabel()

    func setUpUI() {
        // Customize aView
        aView.backgroundColor = UIColor.red
        aView.layer.cornerRadius = 5.0
        aView.clipToBounds = true
        
        // Customize aLabel
        aLabel.text = "Your text"
        aLabel.font = UIFont.boldSystemFont(ofSize: 19.0)
        aLabel.textAlignment = .center
        aLabel.backgroundColor = .orange
    }
}

or

class YourCustomView: UIView {
    let aView: UIView = {
        let view: UIView = UIView()
        view.backgroundColor = UIColor.red
        view.layer.cornerRadius = 5.0
        view.clipToBounds = true
        return view
    }()

    let aLabel: UILabel = {
        let label: UILabel = UILabel()
        label.text = "Your text"
        label.font = UIFont.boldSystemFont(ofSize: 19.0)
        label.textAlignment = .center
        label.backgroundColor = .orange
        return label
    }()
}

With Alacrity we can write something more succinct, without the boilerplate of typical programmatic UI code by taking advantage of its fluent interface

class YourCustomView: UIView {
    let aView: UIView = UIView().avd
        .backgroundColor(UIColor.red)
        .cornerRadius(5.0)
        .view
    
    let aLabel: UILabel = UILabel().acy
        .text("Your text")
        .font(UIFont.boldSystemFont(ofSize: 19.0))
        .textAlignment(.center)
        .backgroundColor(.orange)
        .view
    
}

Requirements

Alacrity requires iOS 10.0 or higher and Swift 3.x

Installation

  1. Add the following to your Podfile:
pod 'Alacrity'
  1. Integrate your dependencies using frameworks: add use_frameworks! to your Podfile.
  2. Run pod install.

Author

Julio Alorro

License

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