3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swift を CLI から実行するまでのメモ(Xcode6.1版)

Posted at

私の環境

  • 手元の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

おわり。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?