Avoid code repetition in constructors by setting a tuple of variables with a 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)
}
}