Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import UIKit
  2.  
  3. extension UIView {
  4.  
  5. public class func componentFromNib<T: UIView>() -> T {
  6. guard let component = Bundle.componentsBundle(for: T.self).loadNibNamed(String(describing: T.self), owner: nil, options: nil)?.first as? T else {
  7. fatalError("Xib not found")
  8. }
  9. return component
  10. }
  11. }
  12.  
  13. extension Bundle {
  14.  
  15. class func componentsBundle(for componentClass: AnyClass) -> Bundle {
  16. if let bundleURL = Bundle(for: componentClass).url(forResource: "AppComponents", withExtension: "bundle"),
  17. let bundle = Bundle(url: bundleURL) {
  18. return bundle
  19. }
  20. if let bundle = Bundle(identifier: "your.framework.bundle.identifier") {
  21. return bundle
  22. }
  23. fatalError("Bundle not found")
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement