There is no standard way building Sketch plugins, not even to mention setting up a Xcode project for Sketch plugin development. Documentation on this sector is not readily available.
Because of that, I previously covered essentials on how we can get started. However, after having to follow it over and over myself, I realized it was nothing but pain lengthy manual process to setup all those configurations and dependancies. Most of us just needed a quick way to experiment some APIs or prove of an immediate concept.
For this sake, I created this Xcode template for you, so that you can get ready on the most important thing to build as easy as possible.
Install The Xcode Templates
In Terminal, enter this command to install the templates to your Xcode user library folder.
git clone http://ift.tt/2oIH4Gj ~/Library/Developer/Xcode/Templates/Sketch\ Plugin
Compiling Your First Sketch Plugin
1. Xcode > New Project > Choose the Sketch Plugin Bundle Template, you should see a few new templates ready.
2. Give it a great name, save to a safe place
At this point, necessary manifest and script files are already setup for you. When you build it, it also gets installed to your Sketch plugins folder in ~/Library/Application\ Support/com.bohemiancoding.sketch3/Plugins
3. Lastly, configure the Executable so that it works with your debugger.
4. Finally, double check the onRun and onSelection method gets called 🙂
Adding Controls To Your Sketch Inpector Panel
The framework default panel simply shows what you have selected
- Add the Framework Target
2. Set target membership of Mocha/CocoaScript.framework to Optional
3. Add Target Dependancy in Your Plugin Bundle
4. Update your manifest, instructions are generated in your framework.js file
5. Test it out!
Customize Your Panel UI
Files in the ? Red group are libraries, you should not change unless you know what you’re doing.
Files in the ? Blue group are supposed to be edited and customised.
You should always almost start with the SketchPanelController.m file.