##Adding Swift Build System
- Open Sublime Text 3
- Go To
Preferences > Browse Packages... - Add a file named
Swift.sublime-buildinsidePackagesdirectory. - Copy the following script in
Swift.sublime-buildfile.
{
"shell_cmd": "xcrun swift $file",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.swift",
}
- Go to
Preferences > Key Bindings-Userand 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.swiftcontaining a single lineprintln("Hello, Swift!"). - Press
command + band you'll be able to see the output. - If you are unable to see the output, go to
Tools > Build Systemsand change it fromAutomatictoSwift, and you should be able to run Swift in ST3.
To ensure build no matter if the path to archive has blank space or not is to put double quotes on
$filein theshell_cmdon theSwift.sublime-buildfile. Thanks for sharing your. scriptThe file would look like this: