ios - 了解 Playground 中的输出

标签 ios swift xcode6.1 swift-playground

为什么下面的代码在Playground中输出如下...

class Vehicle{

    func run(){
        println("Running")//outputs--------- Running
    }
}

var jetta = Vehicle()// outputs ------------ Vehicle
jetta.run()// outputs ---------------------- Vehicle (why not running?)

最后一次调用的输出不应该是“Running”吗?

当我在 swiftstub.com 上尝试相同的代码时或 runswiftlang.com我得到了我期望的结果,但在 Playground 中却没有,为什么?

输出 swiftstub.comrunswiftlang

class Vehicle{

    func run(){
        println("Running")//outputs--------- nothing
    }
}

var jetta = Vehicle()// outputs ------------ nothing
jetta.run()// outputs ---------------------- Running

知道为什么 Playgound 在调用方法 run() 时不输出 Running 吗?

最佳答案

Xcode 中默认显示的右侧面板代表输入的每个表达式的结果。为了显示控制台输出,您需要打开辅助编辑器(alt+command+enter)

enter image description here

关于ios - 了解 Playground 中的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28490827/

相关文章:

ios - iPhone:如何使用Facebook Graph API保存 session

iOS/谷歌广告给出链接器代码失败

iphone - XCode:iOS 兼容性问题

ios - 在 Xcode 中创建带标题的大导航栏

swift - 使用 Firebase 登录时为 "An error occurred while accessing the keychain"

iOS 8.1 模拟器本地化损坏 (NSLocalizedString)

xcode - 查找 "Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0"的原因

ios - SKPayment/SKPaymentQueue : Cannot connect to iTunes Store

ios - 使用 Swift 2 中的面向协议(protocol)编程解析抽象层

ios - SDWebImage 苹果 LLVM 6.0 错误