Skip to content

Instantly share code, notes, and snippets.

@pofat
Created January 5, 2018 09:10
Show Gist options
  • Save pofat/4fbe782c4ff9b0eaa57d6c2f11f128ed to your computer and use it in GitHub Desktop.
Save pofat/4fbe782c4ff9b0eaa57d6c2f11f128ed to your computer and use it in GitHub Desktop.
Better way of adding subviews at once.
/*
From: https://twitter.com/johnsundell/status/948513364015288320?utm_content=buffer67c28&utm_medium=social&utm_source=facebook.com&utm_campaign=buffer
*/
extension UIView {
func add(_ subviews: UIView...) {
subviews.forEach(addSubview)
}
}
/*
//So that you can do
view.add(label, button)
// instead of
view.add(label)
view.add(button)
// Which works well sementically
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment