ios - 在 Swift 中为 DebugPrintable 实现 debugDescription

标签 ios swift lldb

我正在尝试为 Swift 类编写自己的调试描述。我的代码如下所示:

class SceneData : DebugPrintable {
    var fileName : String
    var scene : Scene
    var uuid : String

    var debugDescription: String = {
        return String(format: "<SceneData: {\n  fileName: %s\n  scene: %@\n}>", fileName, scene)
    }
    /*
     * More methods, etc.
     */
}

我收到错误消息 'SceneData.Type' does not have a member named 'fileName',但是 SceneData 很明显确实有一个变量 fileName 上面声明的。尝试在字符串中使用 self 时,我也遇到了类似的问题,我相信这是相关的。

如何在 debugDescription 字符串中正确引用实例变量/self?我很确定这是可能的,因为 other people have said it is ,并且因为让对象的调试描述没有关于自身的任何实际细节似乎很荒谬。我在这里做错了什么?

最佳答案

删除 =,因为它应该是一个计算属性。

var debugDescription: String{
        return String(format: "<SceneData: {\n  fileName: %s\n  scene: %@\n}>", fileName, scene)
}

关于ios - 在 Swift 中为 DebugPrintable 实现 debugDescription,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31867587/

相关文章:

ios - 如何在Swift中从观察对象中提取字符串值

swift - 获取用于事件并发症的时间线条目和模板?

objective-c - lldb 相当于 gdb 的 "follow-fork-mode"或 "detach-on-fork"

c++ - 打印 char 时的 printf 奇怪行为 - LLDB 调试器

ios - NSArray 信号传输

iphone - 清除 NSArrays 的 NSDictionary

ios - 获取文本字段上的 "bottom space to superview"约束

ios - 如何将用户选择的颜色设置为整个 IOS App 的背景色?

python - 在定义的时间后退出 LLDB session

ios - dispatch_async 是否可以中断调用任务