Software Architect / Entrepreneur

Software Architect / Entrepreneur

Fixing the “unrecognized selector sent to instance” exception

Here’s a simple fix for the unrecognized selector exception. Once you understand selectors, it’s straightforward. I’ll walk you through it.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

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

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.

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!

Email Notifications

Never miss a post again! Get my latest articles delivered directly to your inbox and be the first to know about my upcoming course!

Email Notifications

Never miss a post again! Get my latest articles delivered directly to your inbox and be the first to know about my upcoming course!

🙏

Great Choice!

Thanks for enabling notifications! Don’t worry, I hate spam too and I won’t ever disclose your contact information to 3rd parties.