在 Xcode Playground 中,控制右侧栏中的字符串表示?

Posted

技术标签:

【中文标题】在 Xcode Playground 中,控制右侧栏中的字符串表示?【英文标题】:In Xcode playground, control the string representation in the right side column? 【发布时间】:2015-04-27 00:10:03 【问题描述】:

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

【问题讨论】:

有一个DebugPrintable 协议。也许试试? 我刚试过。不是这样的。 您的权利。我也试过了。 【参考方案1】:

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

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

【讨论】:

【参考方案2】:

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

【讨论】:

以上是关于在 Xcode Playground 中,控制右侧栏中的字符串表示?的主要内容,如果未能解决你的问题,请参考以下文章