设置为元组以避免代码重复
通过使用 one liner 设置变量元组,避免构造函数中的代码重复:
class Contact: UIView
{
private var message: UILabel
private var phone: UITextView
required init?(coder aDecoder: NSCoder) {
(message, phone) = self.dynamicType.setUp()
super.init(coder: aDecoder)
}
override func awakeFromNib() {
(message, phone) = self.dynamicType.setUp()
super.awakeFromNib()
}
override init(frame: CGRect) {
(message, phone) = self.dynamicType.setUp()
super.init(frame: frame)
}
private static func setUp(){
let message = UILabel() // ...
let phone = UITextView() // ...
return (message, phone)
}
}