Skip to content
Blake Merryman edited this page Jan 29, 2015 · 2 revisions

Welcome to the Swift Scripts wiki!

This wiki serves as a general knowledge base for the Swift Scripts Repository and for using the Swift programming language to build command line tools and basic scripts.

If you'd like to become a collaborator or have suggestions, please contact Blake Merryman.

If you'd like to see what we have in store for this project, see The Plan.

Overview

All over the web, people are starting to write tutorials for scripting with Swift and there are pieces of the story all over the place. But no one has put them all together. That is the goal of this repository & wiki.

Swift scripting is a bit of a misnomer because at no point is a Swift file actually ever interpreted like a traditional scripting language. Swift files are always compiled into a binary before running. However, depending on the route you choose, you may or may not ever see that binary, which is part of where the "scripting"-feel comes in.

This is not an introduction to the Swift language. If you need a primer, see Apple's official documentation for more information.

Prerequisites

All information in this wiki assumes that you are on a Mac running at least OS X Yosemite (v10.10.1) and Xcode 6.1.1 (with Command Line Tools installed) or that you have set up the appropriate aliases in your path and properly configured your development environment. See this section for more information on the later.

Furthermore, despite needing to have Xcode installed, Xcode is not necessary (and indeed may be a hindrance) for most script/CLT development. Xcode only becomes beneficial when developing large, multi-file scripts/CLTs projects (primarily for code completion).

Only tools needed:

  • Your choice of text editor
  • Terminal.app

The Terminal and Swift

There are four routes for running swift code from the command line:

  1. The REPL,
  2. Executing Inline,
  3. "Interpreting" Scripts, and
  4. Running Compiled Binaries

See each method's page for more details.

Advanced Topics

  • Accepting Arguments
  • Adding a Swift Program to Your Path for Global Access
  • Piping Programs Together

Other Resources:

In this wiki:

  • Developer Environment Setup for Older Versions of Xcode

From Apple:

From the web:

From Github:

Clone this wiki locally