What is lldb_expr in Swift Playground?

橙三吉。 提交于 2019-12-01 22:41:58

问题


I was trying to demonstrate basic inheritance to someone and how the super initializer is always called by default when overriding an init:

class Animal{
    init(){
        println("Animal has been initialized!")
    }
}

class Dog:Animal{
    var feet:Int = 4

    override init(){
        println("Dog has been initialized!")
    }
}

var d = Dog()

Why is it that I get {__lldb_expr_380.Animal feet 4} on the last line? It goes away when I create an instance variable under the animal class.


回答1:


I am not 100% about this but to me this seems sane and logical.

Your Animal class is empty so the compiler needs a way to express / print the class / it's values. So what it does is print __lldb_expr_380.Animal because the compiler doesn't know what else to make of it. If you add a property, for example legs, the result becomes this: {{legs 2} feet 4}.

So, in my understanding whenever you have this empty superclass the compiler will get 'confused' and the error that happens is that it will just print out __llb_expr_:some_number:.ClassName instead of something like {}.

Reference: http://discuss.codewithchris.com/t/episode-7-classes-error---lldb-expr-/150



来源:https://stackoverflow.com/questions/31020725/what-is-lldb-expr-in-swift-playground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!