Skip to content

Instantly share code, notes, and snippets.

@KevinGutowski
Last active August 17, 2019 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KevinGutowski/5ac736b97f00b9de252a916615f6a934 to your computer and use it in GitHub Desktop.
Save KevinGutowski/5ac736b97f00b9de252a916615f6a934 to your computer and use it in GitHub Desktop.
Loading a XIB file in a Sketch plugin
#import "HSMain.h"
@import AppKit;
@implementation HSMain
- (NSString *)helloText {
NSLog(@"HelloSketch (Sketch Plugin)");
return @"Hiya, sending singal from HSMain";
}
- (id)loadNibFile {
// The myNib file must be in the bundle that defines self's class.
NSArray *topLevelObjects;
NSBundle *myBundle = [NSBundle bundleForClass:[HSMain class]];
if (! [myBundle loadNibNamed:@"HSPanel" owner:self topLevelObjects:&topLevelObjects])
{
NSLog(@"Warning! Could not load myNib file.\n");
return NULL;
} else {
return topLevelObjects;
}
}
@end
let sketch = require('sketch')
var onRun = function(context) {
try {
runPlugin()
}
catch(e) {
let pluginURL = context.plugin.url()
let bundlePath = NSBundle.bundleWithURL(pluginURL).resourceURL().path()
let loadFramework = Mocha.sharedRuntime().loadFrameworkWithName_inDirectory('HelloSketch', bundlePath)
console.log(pluginURL, bundlePath, loadFramework)
if (loadFramework) {
runPlugin()
}
}
};
function runPlugin() {
let main = HSMain.alloc().init()
sketch.UI.message(main.helloText())
console.log(main.loadNibFile())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment