7
9

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 をターミナルでざっとペロる #1 Hello World

Last updated at Posted at 2015-04-12

mainimage1.jpg

環境

  • OS X Yosemite 10.10.3
  • Swift 1.2
  • iOS 8.3
  • iTerm 2.0.0

前提

  • App Store で XCode を 最新のものにアップデートしておく (2015年4月12日の時点では上記状態に)

スクリーンショット 2015-04-12 9.02.00.png

ターミナルから swift を呼び出してみる

$ swift
Welcome to Swift version 1.2. Type :help for assistance.

終了は :quit で行える

$ swift
Welcome to Swift version 1.2. Type :help for assistance.
  1> :quit

$

Hello World

Vim などの エディタを開き、以下のように書くよ


println("Hello World!")

swift では 標準出力は println() で行けるようです。
ってことでこれを hello.swift などと言ったようなファイル名で保存するよ。次に、実行は "swift ファイル名" で行うよ

$ swift hello.swift

Hello World

僕の環境では .bash_profile などに PATH を通さなくても動いた。しかもいろいろなサイトを調べてみると、外部スクリプトの実行へは -i のオプションが必要だと書いてあるような記事もあったけど、僕の環境では "swift ファイル名" で実行できた。めでたし!

一応 swift の場所の確認をしておく

まずは Xcode の場所

$ find /Applications -name "Xcode*app" -maxdepth 1

=> /Applications/Xcode.app

この Xcode.app の場所をもとに swift を探す

$ find /Applications/Xcode.app/ -name swift | grep /bin/swift

=> /Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift

もし .bash_profile などに path を通す必要があったりするのならば、見つけた swift の PATH を元に

.bash_profile

export PATH=(/Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/):$PATH

てな感じで。

7
9
1

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
7
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?