7

I have used this in the past.

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)     
{
    self.view.endEditing(true)
}

But now in Xcode 8 beta I get this error:

Declaration touchBegan(touches:withEvent) has different argument names from any potential overrides.

Any thoughts?

Droppy
  • 9,691
  • 1
  • 20
  • 27
Jevon718
  • 354
  • 4
  • 10

1 Answers1

12

This worked for me:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    self.view.endEditing(true)
}

Notice the very subtle Swift 3 updates in the function parameters. On pages 20 and 21 of The Swift Programming Language (Swift 3), they explain that:

“By default, functions use their parameter names as labels for their arguments. Write a custom argument label before the parameter name, or write _ to use no argument label.”

:)

Lucas
  • 880
  • 7
  • 12
  • Thanks I have been trying to find that book for over a month now. It never showed up in my ibooks before. That link you posted is a life saver for me. Have you been able to find that iPad app Playgrounds they have been talking about? – Jevon718 Jun 18 '16 at 16:30
  • @Jevon718 Tim Cook mentioned in the Keynote that it would be available in the Developer preview already. Have you updated your iPad to iOS 10 beta? BTW, don't forget to mark my answer as correct if this helped! :) – Lucas Jun 18 '16 at 16:48