Last active
August 17, 2019 22:21
-
-
Save KevinGutowski/5ac736b97f00b9de252a916615f6a934 to your computer and use it in GitHub Desktop.
Loading a XIB file in a Sketch plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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