Skip to content

Instantly share code, notes, and snippets.

@msoedov
Forked from kavu/swift.sh
Created November 21, 2016 01:43
Show Gist options
  • Save msoedov/91c446a9dbd51ddef7a91eecd8fde885 to your computer and use it in GitHub Desktop.
Save msoedov/91c446a9dbd51ddef7a91eecd8fde885 to your computer and use it in GitHub Desktop.
Minimal Swift command line Hello World
#!/bin/sh
# So you've installed XCode 6 Beta
# Now we could use Swift toolchain to build a minimal
# command line Hellow World
# let's set new Developer Toolchain bundled with Xcode6-Beta.app
# as default toolchain
# sudo xcode-select -s /Applications/Xcode6-Beta.app/Contents/Developer
# alias for Swift binary
# export SWIFT=/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
# simple program
#echo 'println("Hello World")' > swifthello.swift
# build stuff
#$SWIFT -sdk $(xcrun --show-sdk-path --sdk macosx) swifthello.swift
## Thanks to @caius, lines 10-17 now obsolete. Just use `xcrun'
echo 'println("Hello World")' > swifthello.swift
xcrun swift swifthello.swift
# run stuff
./swifthello
# By the way, Swift had a lot of options, invoke with `xcrun swift --help'
# Hope that helps
@jonelf
Copy link

jonelf commented Feb 15, 2024

echo 'print("Hello World")' | swift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment