import Foundation import AppKit class ExportAccessoryView : NSView { } extension NSView { class func fromNib() -> T? { var topLevelObjects : NSArray? guard Bundle.main.loadNibNamed("\(self)", owner: nil, topLevelObjects: &topLevelObjects) else { return nil } return topLevelObjects!.first(where: { $0 is T }) as? T } }