在Xcode playground中,控制右侧列中的字符串表示?

时间:2015-04-27 00:10:04

标签: swift xcode6 swift-playground xcode6.3

我认为Printable协议会这样做,但事实并非如此。还有其他协议吗?我希望它显示3个数字,而不是“C._GLKVector3”

enter image description here

2 个答案:

答案 0 :(得分:2)

从Swift 2开始,这可以通过使类型符合CustomStringConvertible(以前为Printable)来完成。在GLKVector3的情况下,你会这样做:

extension GLKVector3: CustomStringConvertible {
    public var description: String {
        return "<\(x), \(y), \(z)>"
    }
}

enter image description here

答案 1 :(得分:0)

尝试导入XCPlayground有一些东西。 以下是该模块的所有内容:https://developer.apple.com/library/mac/documentation/Swift/Reference/Playground_Ref/Chapters/XCPlayground.html