Why does Xcode line-out autocomplete methods for selector?

我的未来我决定 提交于 2021-02-05 10:50:09

问题


Ever since I upgraded to the latest Xcode, autocomplete lines out (strikethrough) methods for the selector object. I cannot tell if this is a bug with Xcode or there is some new syntax change I'm unaware of. If you plug this into your Playground and erase the method inside #selector(tapHandler(_:)) and re-enter it, does autocomplete line-out the tapHandler(_:) suggestion or not?

class Mango {
    func tap() {
        let tap = UITapGestureRecognizer(target: self, action: #selector(tapHandler(_:)))
    }

    @objc func tapHandler(_ sender: UITapGestureRecognizer) {

    }
}

回答1:


Instead of typing tapH and asking for autocomplete, type self.tapH and ask for autocomplete. The problem goes away.

So, yes, I do rather think it's a bug (unless Swift is changing so that you can't omit the class in a method reference), but there's also an easy workaround.



来源:https://stackoverflow.com/questions/62136806/why-does-xcode-line-out-autocomplete-methods-for-selector

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