-1

I have the following code:

 override func viewDidLoad() {
            super.viewDidLoad()
            //Looks for single or multiple taps.
            let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
            view.addGestureRecognizer(tap)
            // Do any additional setup after loading the view.
        }

func dismissKeyboard() {
    //Causes the view (or one of its embedded text fields) to resign the first responder status.
    view.endEditing(true)
}

When running the application This error occurs when the work of error repair another mistake happens

kvra13
  • 1,019
  • 2
  • 10
  • 16

4 Answers4

3

You are getting this error due to the updates to the swift language, change your tap selector for this:

let tap = UITapGestureRecognizer(target: self, action: #selector(self.dismissKeyboard))

Make sure that the method dismissKeyboard is in the same view controller, if its not you'll need to do #selector(WhateverHasThatMethod.dismissKeyboard)

Also, make sure that the dismissKeyboard method actually exists, it should be something along the lines of:

func dismissKeyboard(){
    YourInputField.endEditing(true)
}
Daniel Ormeño
  • 2,743
  • 2
  • 25
  • 30
0
    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.dismissKeyboard))
guidev
  • 2,695
  • 2
  • 23
  • 44
0

Since Swift 2.2, use this instead: #selector(YourClass.dismissKeyboard)

Lumialxk
  • 6,239
  • 6
  • 24
  • 47
0

Apart from #selector, you can also see some of the new changes in Swift 2.2 from below link:

https://swift.org/blog/swift-2-2-new-features/

will not work in Swift 2.2 but okay in Swift 2.1

override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.rightBarButtonItem =
        UIBarButtonItem(barButtonSystemItem: .Add, target: self,
                        action: "addNewFireflyRefernce")
}

func addNewFireflyReference() {
    gratuitousReferences.append("We should start dealing in black-market beagles.")
}

will work in Swift 2.2 and higher version

override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.rightBarButtonItem =
        UIBarButtonItem(barButtonSystemItem: .Add, target: self,
                        action: #selector(addNewFireflyRefernce))
}

func addNewFireflyReference() {
    gratuitousReferences.append("Curse your sudden but inevitable betrayal!")
}

Also Swift 3.0 is coming soon:

https://swift.org/blog/swift-3-0-release-process/

Narendar Singh Saini
  • 3,555
  • 1
  • 17
  • 17