Xcode 6.3. Внутри класса, реализующего протокол UITextFieldDelegate, я хотел бы переопределить метод touchhesBegan(), чтобы скрыть клавиатуру. Если я избегаю ошибки компилятора в spec функции, то возникает ошибка с интегратором, пытающаяся прочитать "касание" из набора или NSSet, иначе super.touchesBegan(касается, withEvent: event) выдает ошибку. Одна из этих комбинаций скомпилирована в Xcode 6.2! (Итак, где документация для Swift "Set" и как получить элемент из одного?)
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)
Ошибка компилятора: Переопределяющий метод с селектором 'touchhesBegan: withEvent:' имеет несовместимый тип '(NSSet, UIEvent) → ()' и
super.touchesBegan(touches , withEvent:event)
также жалуется
'NSSet' неявно конвертируется в 'Set'; вы хотели использовать 'as' для явного преобразования?
Try:
override func touchesBegan(touches: Set<AnyObject>, withEvent event: UIEvent)
Ошибка компилятора: Тип "AnyObject" не соответствует протоколу "Hashable"
Try:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
Ошибка компилятора в
if let touch = touches.anyObject() as? UITouch
'Set' не имеет члена с именем 'anyObject', но функция spec и вызов super() в порядке!
Try:
override func touchesBegan(touches: NSSet<AnyObject>, withEvent event: UIEvent) -> () or
override func touchesBegan(touches: NSSet<NSObject>, withEvent event: UIEvent)
Ошибка компилятора: Невозможно специализировать нестандартный тип "NSSet"