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
}
이러한 방법으로 작성하게 된다.
반응형
'앱 > Swift' 카테고리의 다른 글
Swift) NSAttributedString, NSMutableAttributedString (1) | 2024.01.01 |
---|---|
UIKit) lineBreakMode에 대해서 (1) | 2024.01.01 |
Swift) DiscardableResult, 알람이 필요없다면! (0) | 2024.01.01 |
UIKit) ReactorKit 을 알아보자(feat. SwiftUI) (1) | 2024.01.01 |
Swift) Associated type (0) | 2024.01.01 |