앱/Swift
UIKit) Then을 사용해보자
진ddang
2024. 1. 1. 21:26
Then은 오픈소스라이브러리로, UIkit의 인스턴스를 생성할때 좀더 깔끔하게 생성하기 위한 라이브러리다.
기존의 UIkit코드는 다음과 같이 보통 사용하게 되는데
let topLabel = UILabel()
topLabel.text = "hi"
topLabel.textColor = .red
혹은
let topLabel: UILabel() {
let label = UILabel()
label.text = "hi"
label.textColor = .red
return label
}()
와 같은 방법으로 생성하게 된다.
이를 좀더 깔끔하게 사용할수 있도록 해주는것이 바로 이 then이다.
let topLabel = UILabel.then {
$0.text = "hi"
$0.textColor = .red
}
이러한 방법으로 작성하게 된다.
반응형