Let's turn Sketch files into code :large_orange_diamond: :soon: :page_with_curl:
##Goal Create a customizable Sketch plugin that converts a selected layer to a UIKit file with Objective-C code.
##Install
Run the deploy.sh
script as sudo (Sketch plugins are under the User's Library folder). This script will copy all the plugins and helper files.
##Build and run
Run the run.sh
script as sudo (same reason). This script will run a deploy.sh
, clear the Console, bring Sketch to focus and execute the plugins shortcut.
##Testing
You can use the Template.sketch
file to play with the plugin and the Sketch2CodeTest
Xcode project to see the view in an iOS environment.
(See sketch2Code.sketchplugin file)
- Store the currently selected item
- Ask the user for a destination folder
- Load the helper descriptors:
view.map
: Tells which Sketch class converted to which UIKit classCommon.snippet
: Tells how a basic (UI) element should be created.UIView
andUITableViewCell.snippet
: Tells how a custom UIView and UITableView file should look like.
- Go through the children of the selected item, for every child:
0. Assemble the interface and implementation files from the snippets
- Create the iVar declaration section
- Create the initialization section
- Create the configuration section, where the view's necessary properties are set
- Create the add to superview code
- Create the layout code
- Write the interface and implementation file to the given file path
##Contacts @csacsi @wiesnerpeti
##Development material
- Sketch Developer portal: http://developer.sketchapp.com/
- Sketch class-dump: https://github.com/ryngonzalez/Sketch-Internals
- Sketch plugin mailing list: http://sketchplugins.com/mailman/listinfo/dev_sketchplugins.com
Sketch is a constant evolving app, this means, that API the plugins can use also changes with it. It is worth to learn how to class-dump the Sketch app to keep up with the changes.