首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在终端中使用swift?

如何在终端中使用swift?
EN

Stack Overflow用户
提问于 2014-06-03 17:04:36
回答 13查看 81.5K关注 0票数 108

我读过What's new in Xcode 6。本文介绍了Xcode6的一些新特性,并表示:

命令行

Xcode的调试器包括Swift语言的交互式版本,称为REPL (Read-Eval-Print-Loop)。使用Swift语法评估正在运行的应用程序并与之交互,或者在类似脚本的环境中编写新代码。REPL可以从Xcode控制台中的LLDB中获得,或者从终端中获得。

我想知道如何获得REPL?

EN

回答 13

Stack Overflow用户

回答已采纳

发布于 2014-06-03 17:34:02

代码语言:javascript
复制
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

然后,您可以执行以下操作之一:

代码语言:javascript
复制
xcrun swift 
lldb --repl

从Xcode6.1开始,在终端中输入swift也会启动REPL。

票数 135
EN

Stack Overflow用户

发布于 2014-06-03 23:54:38

或者,如果你不想弄乱你当前的开发环境,你可以直接运行:

代码语言:javascript
复制
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
票数 57
EN

Stack Overflow用户

发布于 2014-07-13 05:41:55

步骤1:打开终端

第二步:输入"swift“

第三步:没有第三步

示例:

代码语言:javascript
复制
GoldCoast:~ macmark$ swift
Welcome to Swift!  Type :help for assistance.
  1> println("Hello, world")
Hello, world
  2> var myVariable = 42
myVariable: Int = 42
  3> myVariable = 50
  4> let myConstant = 42
myConstant: Int = 42
  5> println(myVariable)
50
  6> let label = "The width is "
label: String = "The width is "
  7> let width = 94
width: Int = 94
  8> let widthLabel = label + String(width)
widthLabel: String = "The width is 94"
  9> :exit

GoldCoast:~ macmark$ 
票数 43
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24011120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档