Declaring conformance to @objc protocol in empty extension breaks with EXC_BAD_INSTRUCTION

。_饼干妹妹 提交于 2019-12-02 05:13:30

I think that the problem is about the Utterable protocol having a property, which is already implemented in the concrete class.

As you probably know, an extension cannot define stored properties (computed only). By adopting the protocol in the extension, something wrong happens - and it is clearly a bug (it should just work or the compiler should raise a compilation error).

To fix it, just adopt the protocol in the class declaration rather than to the extension:

class Bus : Displayable, Utterable { var name = "a bus"; var utterance = "this is a bus"}

extension Bus  {}

Surprisingly, turning the utterance property into a computed one and moving it in the extension body:

extension Bus : Utterable {
    var utterance: String { return "this is a bus" }
}

doesn't solve the problem - still the same error. I consider it as a prove that it's a bug.

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