December 9, 2020 · Swift Xcode iOS Development

Fixing the "unrecognized selector sent to instance" exception

Fixing the "unrecognized selector sent to instance" exception
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket

Ever get this error?

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UhOh.ViewController fireStarted:]: unrecognized selector sent to instance 0x7fe677009df0

A selector is basically a name of a method. So the fireStarted method of the ViewController wasn't found so, the app crashed with that exception.

First look for when this exception was triggered. In my case it was right after hitting a button. So my next check was the storyboard. Click on the button that caused the exception and open up the Connections inspector. Look for the events associated to that button.

Xcode Connections tab
Xcode Connections tab

Now open up the associated view controller.

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
}

Notice how the fireStarted method isn't implemented as an @IBAction in your view controller? That's the problem. Just link it up again and you should be fine.

GIF illustrating how to recreate an IBAction from the Connections tab in the storyboard
Recreating an IBAction

Now you should have:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    @IBAction func fireStarted(_ sender: UIButton) {
    }
}

Just build and you're good to go!

Subscribe by Email

Get my latest content straight to your email

    We won't send you spam. Unsubscribe at any time.
    Powered By ConvertKit
    If you have any questions about this article