iOS 设置为元组以避免代码重复
示例
通过使用一个内衬设置变量元组,避免在构造函数中重复代码:
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) } }