OSX loading of a Nib in Swift

I'm stuck trying to design an application, where I need to reuse various items. Exactly for this purpose I have designed an xib. I followed tons of tutorials, but with none of them I was able to load this Nib in a custom view.


Is there anyone who is able to create a minimum example with Swift 1.2 where there is an xib file with a simple label, which should be loaded into a custom view? Please note that I'm not looking for something for iOS, but for OSX.(I need to use Cocoa)


Thanks in advance,


Misha

It'd be helpful if you could show a code fragment with the code you've tried.


Note that you don't "load [a] Nib in a custom view". Rather, you load a nib which contains a custom view — or, perhaps, contains views that you want to add to an existing custom view as subviews. The nib that you load contains an array of top-level objects, which would typically be the views in question. So, after (say) using 'NSBundle.loadNibNamed:owner:topLevelObjects:' to load the nib and instantiate its contents, you would retrieve the views from the topLevelObjects array, and add them to your view hierarchy.


Alternatively, you can create an instance of the NSNib class directly, then use an instantiate method to get the top level objects. You'd follow this approach, for example, if you wanted to keep the NSNib object in memory so that you can re-instantiate views often and quickly. Otherwise, the simpler NSBundle method above is preferable.

OSX loading of a Nib in Swift
 
 
Q