0
1

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 3 years have passed since last update.

REPLモード

Last updated at Posted at 2021-04-26

SwiftにはREPLモードでプログラムを動かすことができます。

実行方法

ターミナルを開き、

swift

もしくは

xcrun swift

で、Swift REPLモードを起動できます。

ステートメント

  1> let name = "Tanaka"
name: String = "Tanaka"
  2> print("Hello, \(name)")
Hello, Tanaka

Swiftのステートメントを入力すると、REPLEは対話形式で応答します。

関数

5> func sample(name: String) {
6.	return name
7. }  

REPLでは関数も書くことができます。
関数をかく時は、最初の一文の行番号には最後に>がつきます。関数ステートメントのように、連続する行のステートメントは、行番号の後ろに.ピリオドがつきます。

終了方法

REPLを終了したい時は、

:exit

で終了することができます。

まとめ

実際の開発で使うことはほとんどないですが、何か新しい技術や計算処理を実験したい時などは、PlaygroundやREPLが使えそうです。

参考

[増補改訂第3版]Swift実践入門 ── 直感的な文法と安全性を兼ね備えた言語 (WEB+DB PRESS plusシリーズ) 

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?