Swift DSL for UIKit
Branch: master
Clone or download
Latest commit 444f474 Jan 23, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example README updated Jan 20, 2019
UIKitSwiftDSL/Classes @discardableResult annotation removed from root stack and view functi… Jan 22, 2019
.gitignore Initial commit Jan 20, 2019
LICENSE Initial commit Jan 20, 2019
README.md README updated. Jan 21, 2019
UIKitSwiftDSL.podspec bump version Jan 22, 2019



Version Carthage compatible License Platform

Swift DSL for UIKit. Simple DSL in Swift which gives you opportunity to write layout code in readable and declarative way.


let rootView = stack {
    $0.spacing = 16
    $0.axis = .vertical
    $0.isLayoutMarginsRelativeArrangement = true

    $0.stack {
        $0.distribution = .fillEqually
        $0.axis = .horizontal

        $0.label {
            $0.textAlignment = .center
            $0.textColor = .white
            $0.text = "Hello"

        $0.label {
            $0.textAlignment = .center
            $0.textColor = .white
            $0.text = "World"

        $0.customLabel {
            $0.textAlignment = .center
            $0.textColor = .white
            $0.text = "!!!"

    let messageButton = $0.button {
        $0.tintColor = .white
        $0.setTitle("Say Hi!", for: .normal)

    $0.view {
        $0.backgroundColor = .clear

Custom View

If you are using some Custom Views in your project you can easily add it to support DSL.

import UIKitSwiftDSL

class CustomLabel: UILabel {
// Custom implementation here

extension UIView {
    func customLabel(apply closure: (CustomLabel) -> Void) -> CustomLabel {
        return custom(CustomLabel(), apply: closure)


UIKitSwiftDSL doesn't have any logic related to AutoLayout. You can use any library you want.

$0.button {
    $0.tintColor = .white
    $0.setTitle("Say Hi!", for: .normal)
    // Add your AutoLayout code here.


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


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

pod 'UIKitSwiftDSL'

UIKitSwiftDSL is available through Carthage. To install it, simply add the following line to your Cartfile:

github "mecid/UIKitSwiftDSL"


Majid Jabrayilov, cmecid@gmail.com


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