kvra13 kvra13 - 4 months ago 16x
iOS Question

Use of string literal for Objective-C selectors is deprecated; use '#selector' instead

I have the following code:

override func viewDidLoad() {
//Looks for single or multiple taps.
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
// 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.

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


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(){