问题
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 suggestion or not?tapHandler(_:)
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