为什么我的 Printable 实现在 Swift playground 中不起作用?
Why is my Printable implementation not working in Swift playground?
在 Swift 游乐场中考虑这段代码:
import Cocoa
class Thing: Printable {
let name: String
init() {
name = "something"
}
var description: String { return name }
}
let a = Thing()
println("hello, \(a)")
作为图像:
预期:我希望最后一行打印 "hello, something"。
观察到:它打印 "hello, __lldb_expr_1.Thing" 就好像我没有实现 Printable 协议一样。
该代码实际上在真实 iOS 应用程序的上下文中工作,它按预期使用 Printable 协议打印 "hello, something"。
为什么这段代码没有打印出我在 playground 中期望的内容?这是游乐场的限制吗?
我认为此错误已在 Swift 1.2 中修复
在 Swift 游乐场中考虑这段代码:
import Cocoa
class Thing: Printable {
let name: String
init() {
name = "something"
}
var description: String { return name }
}
let a = Thing()
println("hello, \(a)")
作为图像:
预期:我希望最后一行打印 "hello, something"。
观察到:它打印 "hello, __lldb_expr_1.Thing" 就好像我没有实现 Printable 协议一样。
该代码实际上在真实 iOS 应用程序的上下文中工作,它按预期使用 Printable 协议打印 "hello, something"。
为什么这段代码没有打印出我在 playground 中期望的内容?这是游乐场的限制吗?
我认为此错误已在 Swift 1.2 中修复