Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- extension UIView {
- public class func componentFromNib<T: UIView>() -> T {
- guard let component = Bundle.componentsBundle(for: T.self).loadNibNamed(String(describing: T.self), owner: nil, options: nil)?.first as? T else {
- fatalError("Xib not found")
- }
- return component
- }
- }
- extension Bundle {
- class func componentsBundle(for componentClass: AnyClass) -> Bundle {
- if let bundleURL = Bundle(for: componentClass).url(forResource: "AppComponents", withExtension: "bundle"),
- let bundle = Bundle(url: bundleURL) {
- return bundle
- }
- if let bundle = Bundle(identifier: "your.framework.bundle.identifier") {
- return bundle
- }
- fatalError("Bundle not found")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement