Subclass NSView and make it conform to NibLoadable.
Conformance makes the default implementation available to you.
Make sure the XIB file name and your View name are same
// For views that can be loaded from nib fileprotocolNibLoadable{// Name of the nib filestaticvarnibName:String{get}staticfunccreateFromNib(inbundle:Bundle)->Self}extensionNibLoadablewhereSelf:NSView{// Default nib name must be same as class namestaticvarnibName:String{returnString(describing:Self.self)}staticfunccreateFromNib(inbundle:Bundle=Bundle.main)->Self{vartopLevelArray:NSArray?=nilbundle.loadNibNamed(NSNib.Name(nibName),owner:self,topLevelObjects:&topLevelArray)letviews=Array<Any>(topLevelArray!).filter{$0isSelf}returnviews.lastas!Self}}