Xcode 6.3. Inside a class that implements the UITextFieldDelegate protocol, I would like to override the touchhesBegan () method to hide the keyboard. If I avoid a compiler error in the spec function, an error occurs with the integrator trying to read the βtouchβ from the set or NSSet, otherwise super.touchesBegan (concerns, withEvent: event) throws an error. One of these combinations compiled in Xcode 6.2! (So, where is the documentation for Swift "Set" and how to get an element from one?)
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
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 'touchhesBegan: withEvent:' has an incompatible type '(NSSet, UIEvent) β ()' and
super.touchesBegan(touches , withEvent:event)
also complains
'NSSet' is implicitly converted to 'Set'; did you want to use 'as' for explicit conversion?
Try:
override func touchesBegan(touches: Set<AnyObject>, withEvent event: UIEvent)
Compiler Error: Type "AnyObject" does not conform to the "Hashable" protocol
Try:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
Compiler error in
if let touch = touches.anyObject() as? UITouch
'Set' does not have a member named 'anyObject', but the spec function and calling super () are fine!
Try:
override func touchesBegan(touches: NSSet<AnyObject>, withEvent event: UIEvent) -> () or override func touchesBegan(touches: NSSet<NSObject>, withEvent event: UIEvent)
Compiler Error: Unable to specialize non-standard type "NSSet"