Quick reminder about Objective-C selectors

Quick reminder about Objective-C selectors
4 years, 11 months ago 0
Posted in: Programming

So I spent a good 15 minutes scratching my head over an exception being thrown in Xcode:
 

-[ViewController playMovieFinished]: unrecognized selector sent to instance 0x7d52e20

2012-03-12 16:14:50.321 MediaPlayground[10032:11f03] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[ViewController playMovieFinished]: unrecognized selector sent to instance 0x7d52e20’

So naturally I go to the playMovieFinished method and take a look at the selector being defined. Everything looked okay to me. After doing some digging around, I finally figured out what the problem was and it was a really dumb one. Turns out I was missing a : at the end of the selector method name.

The Method in Question:

- (void)playMovieFinished:(NSNotification *)theNotification;

What I Had:

selector:@selector(playMovieFinished)

What I Needed:

selector:@selector(playMovieFinished:)

This is just a quick reminder that could save precious time debugging little things that the compiler should really flag down. Also this only applies to methods with arguments.

For methods with no arguments to be used as selectors, no : is needed.

The Parameterless Method:

- (void)playMovieFinished;

What is Needed:

selector:@selector(playMovieFinished)
Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *