美文网首页
REPL:Swift交互式解释器

REPL:Swift交互式解释器

作者: 黑白森林无间道 | 来源:发表于2020-09-06 23:14 被阅读0次

Xcode6.1引入的以交互式的方式来体验swift的方法
Read Eval PrintLoop:简称REPL

REPL快捷键

  • 退出 :quit :q
  • 帮助 :help
  • 将光标移动到当前行的开始处 Control+A
  • 将光标移动到当前行的开始处 Control+E

示例代码

% swift
Welcome to Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9).
Type :help for assistance.
  1> let a = "100"
a: String = "100"
  2> Int(a)
$R0: Int? = 100
  3> let b = $R0 + 50
error: repl.swift:3:9: error: value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let b = $R0 + 50
        ^

repl.swift:3:9: note: coalesce using '??' to provide a default when the optional value contains 'nil'
let b = $R0 + 50
        ^
        (   ?? <#default value#>)

repl.swift:3:9: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
let b = $R0 + 50
        ^
           !


  3> let b = $R0! + 50
b: Int = 150
4> func addTwoNumbers(num1:Int, num2:Int) -> Int { 
  5.     return num1 + num2 
  6. } 
  7> let sum = addTwoNumbers(num1: 100, num2: 50)
sum: Int = 150

相关文章

  • swift总结2-REPL

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

  • REPL:Swift 交互式解释器

    REPL 简介 Xcode 6.1 引入了另外一种以交互式的方式来体验 Swift 的方法Read Eval Pr...

  • REPL:Swift交互式解释器

    Xcode6.1引入的以交互式的方式来体验swift的方法Read Eval PrintLoop:简称REPL R...

  • nodeJS基础

    Node.js REPL(交互式解释器) Node.js REPL(Read Eval Print Loop:交互...

  • node.js学习(3)-REPL

    1.Node.js REPL(交互式解释器) Node.js REPL(Read Eval Print Loop:...

  • node.js(五)

    Node.js REPL(交互式解释器) Node.js REPL(Read Eval Print Loop:交互...

  • Node.js-REPL(交互式解释器)

    什么是REPL? REPL : Read Eval Print Loop : 交互式解释器。表示电脑的一个环境,类...

  • repl(交互式解释器)

    REPL(Read Eval Print Loop:交互式解释器)概念 表示一个电脑的环境,类似 Window 系...

  • Node REPL

    REPL(Read Eval Print Loop,交互式解释器)是一个处理 Node.js 表达式的交互式 sh...

  • nodejs学习

    Node.js REPL Read Eval Print Loop交互式解释器,可进行读取,执行,打印,循环等任务...

网友评论

      本文标题:REPL:Swift交互式解释器

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