为什么 Xcode 为选择器列出自动完成方法? [英] Why does Xcode line-out autocomplete methods for selector?
问题描述
自从我升级到最新的 Xcode,自动完成为 selector
对象列出(删除线)方法.我不知道这是 Xcode 的错误还是有一些我不知道的新语法更改.如果你将它插入你的 Playground 并删除 #selector(tapHandler(_:))
中的方法并重新输入它,是否自动完成将 建议与否?tapHandler(_:)
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) {
}
}
推荐答案
不要输入 tapH
并要求自动完成,而是输入 self.tapH
并要求自动完成.问题迎刃而解.
Instead of typing tapH
and asking for autocomplete, type self.tapH
and ask for autocomplete. The problem goes away.
所以,是的,我更愿意认为这是一个错误(除非 Swift 进行了更改,因此您不能在方法引用中省略该类),但也有一个简单的解决方法.
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.
这篇关于为什么 Xcode 为选择器列出自动完成方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!