DHDeclarable

Declarative UIKit for iOS apps

View the Project on GitHub dan-hart/DHDeclarable

Introduction to DHDeclarable

@discardableResult func declaredWith(_ then: (_ instance: Self) -> Void) -> Self {
    then(self)
    return self
}

Not using DHDeclarable

let stackView = UIStackView()
stackView.axis = .vertical
stackView.distribution = .fill
stackView.spacing = 10
stackView.addArrangedSubview(...)
stackView.addArrangedSubview(...)
stackView.addArrangedSubview(...)
return stackView

Using DHDeclarable

return UIStackView().declaredWith {​​​​​​​​​​​​​​​​​​​​​​​​​ stack in
    stack.axis = .vertical
    stack.distribution = .fill
    stack.spacing = 10
    stack.addArrangedSubview(...)
    stack.addArrangedSubview(...)
    stack.addArrangedSubview(...)
}

Notes:

Why use DHDeclarable?

Continue learning about DHDeclarable in the next article: Building on the Basics, or view the map.