Skip to content

Instantly share code, notes, and snippets.

@blakemerryman
Forked from Star-Lord-XIII/SwiftInST3.md
Last active June 18, 2018 20:41
Show Gist options
  • Save blakemerryman/5ff3e1064ca575a5000a09bc7588a417 to your computer and use it in GitHub Desktop.
Save blakemerryman/5ff3e1064ca575a5000a09bc7588a417 to your computer and use it in GitHub Desktop.
Running Swift scripts from Sublime Text 3 in MacOSX10.11

Adding Swift Build System

  • Open Sublime Text 3
  • Go To Preferences > Browse Packages...
  • Add a file named Swift.sublime-build inside Packages directory.
  • Copy the following script in Swift.sublime-build file.
{
 	"shell_cmd": "xcrun swift \"$file\"",
 	"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
 	"working_dir": "${file_path}",
 	"selector": "source.swift",
}
  • Go to Preferences > Key Bindings-User and add the following script to it.
{
	"keys": ["super+b"], 
	"command": "build",
	"context": [
		{ "key": "selector", "operator": "equal", "operand": "source.swift" }
	], 
	"args": {
		"build_system": "Packages/Swift.sublime-build",
		"variant": "Build"
	}
}

You are ready to run Swift scripts from ST3 now.

Testing the Swift Build System

  • Create a file A.swift containing a single line println("Hello, Swift!").
  • Press command + b and you'll be able to see the output.
  • If you are unable to see the output, go to Tools > Build Systems and change it from Automatic to Swift, and you should be able to run Swift in ST3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment