swift 通过protocol快速写view

import UIKit

protocol NibLoadable {}

extension NibLoadable where Self: UIView {
    static func loadViewFromNib() -> Self {
        return Bundle.main.loadNibNamed("\(self)", owner: nil, options: nil)?.first as! Self
    }
}

你可能感兴趣的:(swift 通过protocol快速写view)