Swift REPL

作者: 赏味不足 | 来源:发表于2016-11-16 10:42 被阅读89次

什么是REPL

当初最早升级Xcode6.1的时候就在Command Line Tool中增加了这个特性来辅助Swift开发,全称叫做Read Eval Print Loop。其实和我们之前提到的groovysh和python是一样的一个特性,属于交互性模式,但是swift这个REPL使用下来却是体验最好的一个。可惜当初在OSX 10.9的版本时候提示需要10.10才可以使用。所以现在我们在OS X Yosemite下就可以正常使用

实践

我们在终端中输入xcrun swift即可唤起这个交互模式

swift1swift1

我们来写个简单的例子来看看REPL的一些反馈和效果

swift2swift2

多行的例子,这里使用了隐性定义字符串的方式。

swift3swift3 swift4swift4

另外我们如果定义一个方法的话,这个也是我觉得体验很好的一点,如下

swift5swift5

另外如果需要使用上面写过的方法或者重新要调试的话,可以通过上下进行整个方法每一行的调用。如下

swift6swift6

更多REPL的快捷键

Arrow Keys        Move cursor left/right/up/down
Control+F        Move cursor right one character, same as right arrow
Control+B        Move cursor left one character, same as left arrow
Control+N        Move cursor to end of next line, same as down arrow
Control+P        Move cursor to end of prior line, same as up arrow
Control+D        Delete the character under the cursor
Option+Left        Move cursor to start of prior word
Option+Right    Move cursor to start of next word
Control+A        Move cursor to start of current line
Control+E        Move cursor to end of current line
Delete            Delete the character to the left of the cursor
Esc <            Move cursor to start of first line
Esc >            Move cursor to end of last line

相关文章

  • Swift 起步

    原文来自Swift官方网站 查看版本 REPL 如果想运行没有参数的Swift指令,你可以使用REPL(Read-...

  • Swift REPL

    什么是REPL 当初最早升级Xcode6.1的时候就在Command Line Tool中增加了这个特性来辅助Sw...

  • swift学习一

    1、在MacOS上进入REPL环境: 2、SPM(swift package manager) The Swift...

  • Swift4.0 入门-第一个Swift程序

    使用Swift REPL REPL是英文Read-Eval-Print Loop的缩写,一种简单的交互式运行编译环...

  • Swift 命令行工具

    // Swift 命令行工具 // REPL环境 就是每输入一句语句就立即执行和输出 // REPL环境只是表现的...

  • Swift on Linux —— REPL

    如果你已经在 Linux 安装完成 Swift,那么可以开始阅读本文。 If not,请阅读此文。 REPL RE...

  • Swift Tips:三、Swift开发环境

    Swift命令行工具 终端上可以使用Swift的REPL(Real-Eval-Print Loog)环境,输入一句...

  • Swift-REPL介绍

    1.REPL 1.1 交互式环境-REPL: REPL是Read-Eval-Print-Loop(读取-执行-输出...

  • 终端直接输入swift提示异常

    问题如下 在终端直接使用swift命令行,提示异常error: failed to launch REPL pro...

  • swift总结2-REPL

    REPL是read eval print loop的缩写,swift的交互式解释器1.启用的方法,在终端中直接输入...

网友评论

    本文标题:Swift REPL

    本文链接:https://www.haomeiwen.com/subject/ivxrpttx.html