Skip to content

Instantly share code, notes, and snippets.

@GoranLilja
Created August 8, 2019 06:15
Show Gist options
  • Save GoranLilja/e924955c5c4b1b16105e103824cb4eb7 to your computer and use it in GitHub Desktop.
Save GoranLilja/e924955c5c4b1b16105e103824cb4eb7 to your computer and use it in GitHub Desktop.
import UIKit
func create<T>(_ input: T? = nil, _ setup: ((T) -> Void)) -> T where T: NSObject {
let obj = input ?? T()
setup(obj)
return obj
}
func create<T>(_ input: T? = nil, _ setup: ((T) -> Void)) -> T where T: UIView {
let obj = input ?? T()
obj.translatesAutoresizingMaskIntoConstraints = false
setup(obj)
return obj
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment