Skip to content

Instantly share code, notes, and snippets.

@kazmiekr
Created March 18, 2016 13:54
Show Gist options
  • Select an option

  • Save kazmiekr/64ce00aa29c2c9078aaf to your computer and use it in GitHub Desktop.

Select an option

Save kazmiekr/64ce00aa29c2c9078aaf to your computer and use it in GitHub Desktop.
Shell script to run a swift Xcode playground
#!/bin/bash
function error_exit {
echo "$1"
exit 1
}
function clean_dir {
rm $MAIN_SWIFT_FILE
}
if [ "$1" == "" ]; then
error_exit "Directory is required to run"
fi
MAIN_SWIFT_FILE="$1main.swift"
PLAYGROUND_MAIN_SWIFT_FILE="$1Contents.swift"
PLAYGROUND_SWIFT_SOURCES_DIR="$1Sources"
OUTPUT_EXECUTABLE="$1playground"
SWIFT_COMPILER_ARGS="$MAIN_SWIFT_FILE -o $OUTPUT_EXECUTABLE"
echo "Compiling playground: $1"
cp $PLAYGROUND_MAIN_SWIFT_FILE $MAIN_SWIFT_FILE
# Check to see if we need to include sources
if [ -d "$PLAYGROUND_SWIFT_SOURCES_DIR" ]; then
SWIFT_COMPILER_ARGS="$PLAYGROUND_SWIFT_SOURCES_DIR/**/*.swift $SWIFT_COMPILER_ARGS"
fi
echo "Compiler statement: swiftc $SWIFT_COMPILER_ARGS"
if swiftc $SWIFT_COMPILER_ARGS; then
clean_dir
echo $'Running playground\n\n'
./$OUTPUT_EXECUTABLE
else
clean_dir
error_exit "Compile failed"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment