0

So I have an old app that needs to be updated and this was the original code that worked:

myBtn.addTarget(nil, action:("addNewObject"), for:.touchUpInside)

"addNewObject" is a function common in several different classes of which an instance of myBtn will exist. However after trying to update the code to Swift 3 as below, I now get the "Use of unresolved identifier" error.

myBtn.addTarget(nil, action:(#selector(addNewObject)), for:.touchUpInside)
JeremyRaven
  • 119
  • 1
  • 10

2 Answers2

0

You should not use nil, use self

myBtn.addTarget(self, action: #selector(addNewObject), for: .touchUpInside)

Implement addNewObject method like this,

@IBAction func addNewObject() {
    //Your code goes here
}
PPL
  • 6,357
  • 1
  • 11
  • 30
0

The target can not be nil. Change "nil" to "self".

myBtn.addTarget(self, action: (#selector(addNewObject)), for: .touchUpInside)
Keyur Tailor
  • 424
  • 3
  • 16