- 解决继承的烦恼
- 解决依赖性
利用Protocol的特性扩展
protocol Nibloadable {
}
extension Nibloadable where Self : UIView {
static func loadFromNib(_ nibName : String? = nil) -> Self {
guard nibName != nil else {
return Bundle.main.loadNibNamed("\(self)", owner: nil, options: nil)?.first as! Self
}
return Bundle.main.loadNibNamed(nibName!, owner: nil, options: nil)?.first as! Self
}
}
网友评论