NibUtil.swift 715 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // NibUtil.swift
  3. // HCQuanfangtong
  4. //
  5. // Created by Apple on 2021/12/29.
  6. // Copyright © 2021 Jyp. All rights reserved.
  7. //
  8. import UIKit
  9. extension UINib{
  10. static func loadNib<T>(_ type : T.Type) -> UINib{
  11. return UINib.init(nibName: String(describing: type), bundle: nil)
  12. }
  13. static func view<T>(withType type : T.Type) -> T?{
  14. return loadNib(type).instantiate(withOwner: nil, options: nil).last as? T
  15. }
  16. }
  17. extension NSObject{
  18. var className:String{
  19. get{
  20. let name = type(of: self).description()
  21. if name.contains("."){
  22. return name.components(separatedBy: ".")[1]
  23. }
  24. return name
  25. }
  26. }
  27. }