Skip to content

Instantly share code, notes, and snippets.

@efremidze
Last active March 12, 2017 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efremidze/13c11819e83cb718834c7f212992f01f to your computer and use it in GitHub Desktop.
Save efremidze/13c11819e83cb718834c7f212992f01f to your computer and use it in GitHub Desktop.
protocol Constrainable {}
extension Constrainable where Self: UIView {
@discardableResult
func constrain(constraints: (Self) -> [NSLayoutConstraint]) -> [NSLayoutConstraint] {
let constraints = constraints(self)
self.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate(constraints)
return constraints
}
}
extension UIView: Constrainable {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment