Szwedo
Szwedo

Reputation: 364

Object not implementing method

If a message is sent to an object, but the object does not implement that method what is the next step?

Upvotes: 0

Views: 80

Answers (3)

MadhavanRP
MadhavanRP

Reputation: 2830

You should call respondsToSelector: on the object first to tackle that situation. That way you can handle cases where the object does not respond.

if([object respondsToSelector:@selector(method)]
   {
       //code here
   }
else
   {
       //code here
   }

Upvotes: 0

jrturton
jrturton

Reputation: 119292

A crash, caused by unrecognised selector sent to instance.

Upvotes: 1

Mike K
Mike K

Reputation: 2227

you'll get an exception. it should tell you what the selector (message) is, so check to see whether you've misspelled it when you call the method, or when you declare the method in the object's class.

Upvotes: 0

Related Questions