I added some features to Sketch-NibUITemplate that might be of interest to plugin developers. You can now use nibs with outlets, actions and bindings!
The code is here: https://github.com/aparajita/sketch-style-master/blob/master/src/lib/sketch-nibui.js
The key changes from the original version:
ibtool as part of the build process to automatically convert the xib to a nib, and to write a JSON file with the outlets and connections. That code is here: https://github.com/aparajita/sketch-style-master/tree/master/webpack-lib/loaders. I made webpack loaders to deal with this, it could just as easily be in a shell script, standalone node file, etc.
All outlets defined in the
.m file are automatically available via
[NibUI instance].outlets.[outlet name]. For safety, I felt it was better to keep them in a separate namespace rather then put them directly on the NibUI instance.
When instantiating NibUI, you pass an object you want actions and NS delegate methods to delegate to. The following NS delegate methods will automatically be called on the delegate object if they exist:
If there is a ‘window’ outlet defined:
For each editable NSTextView that has a tag > 0:
The action methods defined in the
.m file, if they exist in the delegate object, are called automatically.
When instantiating NibUI, you can pass a dictionary of ivar names and default values. These are used to create actual ivars in the nib owner proxy class, and are available via
I use all of these capabilities in the plugin at https://github.com/aparajita/sketch-style-master. The Xcode project is at https://github.com/aparajita/sketch-style-master/tree/master/src/nib. The code showing usage of all this is at https://github.com/aparajita/sketch-style-master/blob/master/src/lib/shared-style-renamer.js.
The actual plugin is called 'Style Master', available via Runner.
Hope you find this useful.