Swift初始化语法糖库Then,使初始化代码更简洁。
使用Then初始化UILabel并设置其属性:
let label = UILabel().then { $0.textAlignment = .center $0.textColor = .black $0.text = "Hello, World!" }这相当于:
let label: UILabel = { let label = UILabel() label.textAlignment = .center label.textColor = .black label.text = "Hello, World!" return label }()