Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 8 - Make the keyboard go away when a user clicks on the background

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?

like image 206
Jevon718 Avatar asked Jun 18 '16 08:06

Jevon718


1 Answers

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.”

:)

like image 148
Lucas Avatar answered Nov 11 '22 09:11

Lucas