Home > Back-end >  Same code in one project works, fails in 2nd project: Thread 1: "-[Destini_iOS13.ViewController
Same code in one project works, fails in 2nd project: Thread 1: "-[Destini_iOS13.ViewController

Time:11-11

I'm brand new to Swift programming. I'm doing a Udemy project and have copied all the exact same code from their "completed" project (which builds and runs fine) into my "learning" project and it fails with error:

Thread 1: "-[Destini_iOS13.ViewController IBAction:]: unrecognized selector sent to instance 0x15ff0c250"

It's a very simple program and I have no idea why the identical code works in one but not the other. Is this some broken link or resource? Any ideas?

CodePudding user response:

It sounds like a button in Main.storyboard is linked to a method not in the ViewController class.

To fix this -

  1. Right click on the button within the storyboard file to bring up a list of links/connections to it.
  2. Remove all items listed under Sent Events (I'm assuming it's just the item listed for Touch Up Inside, but remove others as well if they're there)
  3. Right-click and drag from the button to inside the ViewController file:
    • If the @IBAction function you want's already listed, drag over it until it's highlighted.
    • If you want to create a new @IBAction function, drag it to an empty line inside the ViewController class.
  • Related