私の環境
- 手元のOS:
Mac OS X 10.9.5 (Mavericks)
- Xcode:
6.1
手順
-
Swift のパスを確認
$ find /Applications/Xcode.app/ -name swift /Applications/Xcode.app//Contents/Developer/Documentation/DocSets/com.apple.adc.documentation.AppleiOS8.1.iOSLibrary.docset/Contents/Resources/Tokens/swift /Applications/Xcode.app//Contents/Developer/Documentation/DocSets/com.apple.adc.documentation.AppleOSX10.10.CoreReference.docset/Contents/Resources/Tokens/swift /Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift /Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift
この中だと、恐らく
/Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
がそう。 -
パスを通す
$ export PATH=/Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/:$PATH
もしくは
~/.bash_profile
等に追記
使ってみる
ヘルプの表示
$ swift --help
OVERVIEW: Swift compiler
USAGE: swift [options] <inputs>
OPTIONS:
-assert-config <value> Specify the assert_configuration replacement. Possible values are Debug, Release, Replacement.
-D <value> Specifies one or more build configuration options
-framework <value> Specifies a framework which should be linked against
-F <value> Add directory to framework search path
〜
スクリプトファイルの実行
hello.swift
println("hello world")
ファイルを保存したら、コマンドラインから実行。
-i
オプションは Xcode 6.1 から?不要になったぽい。
$ swift hello.swift
hello world
ほか
学習するには、Appleの公式リファレンスを読めばよい。
⇒ The Swift Programming Language
おわり。