Xcode 6.3.在实现UITextFieldDelegate协议的类中,我想重写touch chesBegan()方法以可能隐藏键盘.如果我在函数规范中避免了编译器错误,那么try 从Set或NSSet读取"touch"时会出现编译器错误,否则super.touch chesBegan(touch,with Event:event)会抛出错误.这些组合之一是用Xcode6.2编译的!(那么,SWIFT的文档在哪里"设置",以及如何从其中获取元素?)
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
// Hiding the Keyboard when the User Taps the Background
if let touch = touches.anyObject() as? UITouch {
if nameTF.isFirstResponder() && touch.view != nameTF {
nameTF.resignFirstResponder();
}
}
super.touchesBegan(touches , withEvent:event)
}
try :
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) or
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent)
Compiler error: Overriding method with selector 'touchesBegan:withEvent:' has incompatible type '(NSSet, UIEvent) -> ()' and
super.touchesBegan(touches , withEvent:event)
也在抱怨
"NSSet"不能隐式转换为"Set";是否要使用"As"显式转换?
try :
override func touchesBegan(touches: Set<AnyObject>, withEvent event: UIEvent)
编译器错误: 类型"AnyObject"不符合协议"Hasable"
try :
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
编译器错误在
if let touch = touches.anyObject() as? UITouch
"set"没有名为"anyObject"的成员,但是函数规范和对Super()的调用都是正常的!
try :
override func touchesBegan(touches: NSSet<AnyObject>, withEvent event: UIEvent) -> () or
override func touchesBegan(touches: NSSet<NSObject>, withEvent event: UIEvent)
编译器错误: 无法专门化非泛型类型""NSSet""