I tried write a static method for UIView which instantiates view of that class from the nib. Method should be generic and work on every UIView
subclasses. Also I wa
Use following code should be ok(in Swift 3):
protocol Nibable {}
extension Nibable {
static func loadFromNib() -> Self? {
return Bundle.main.loadNibNamed(String(describing:
type(of:Self.self)), owner: nil, options: nil)?.first as? Self
}
}
final class ViewFromNib: UIView {}
extension ViewFromNib: Nibable {}
var nibView = ViewFromNib.loadFromNib()