클로저 사용 이유: 변수 정의, 설정, 초기화 코드가 간결해져서 읽기 쉬어지기 때문에
let helloLabel: UILabel = { let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false label.text = "Hello, World" return label }() //클로저 스타일 라벨 설정
let myNameButton: UIButton = { let button = UIButton(type: .system) button.translatesAutoresizingMaskIntoConstraints = false button.setTitle("Press me", for: .normal) button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) return button }() //클로저 스타일 버튼 설정
위 코드에 대한 제약조건은 따로 설정해야한다.