More than 3 years have passed since last update.

swift コマンドが Yosemite から /usr/bin/swift に標準で入っていた。


(→ Yosemite をクリーンインストールしたところちゃんと入っていました!)

$ which swift


まずは --help で引数をチェック。

$ swift --help

OVERVIEW: Swift compiler

USAGE: swift [options] <inputs>

-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
-g Emit debug info
-help Display available options
-I <value> Add directory to the import search path
-j <n> Number of commands to execute in parallel
-L <value> Add directory to library link search path
-l<value> Specifies a library which should be linked against
-module-cache-path <value>
Specifies the Clang module cache path
-module-link-name <value>
Library to link against when using this module
-module-name <value> Name of the module to build
-nostdimport Don't search the standard library import path for modules
-Onone Compile without any optimization
-Ounchecked Compile with optimizations and remove runtime safety checks
-O Compile with optimizations
-sdk <sdk> Compile against <sdk>
-target-cpu <value> Generate code for a particular CPU variant
-target <value> Generate code for the given target
-version Print version information and exit
-v Show commands to run and use verbose output
-Xcc <arg> Pass <arg> to the C/C++/Objective-C compiler
-Xlinker <value> Specifies an option which should be passed to the linker

引数なしでインタラクティブなREPL(Read Eval Print Loop)モードに入る。

$ swift

Welcome to Swift! Type :help for assistance.

(終了時は Control+d か、:q を入力。)


import Cocoa 書けば OS X コンポーネントも使える。


import Cocoa

let alert = NSAlert()
alert.messageText = "エラー!"

スクリーンショット 2014-11-12 21.33.10.png