NibLoadable.swift 453 B

12345678910111213141516171819
  1. //
  2. // NibLoadable.swift
  3. // SwiftBilibili
  4. //
  5. // Created by 罗文 on 2021/1/15.
  6. // Copyright © 2021年 罗文. All rights reserved.
  7. //
  8. import UIKit
  9. protocol NibLoadable{}
  10. extension NibLoadable where Self : UIView {
  11. static func loadFromNib(_ nibname : String? = nil) -> Self {
  12. let loadName = nibname == nil ? "\(self)" : nibname!
  13. return Bundle.main.loadNibNamed(loadName, owner: nil, options: nil)?.first as! Self
  14. }
  15. }