Tuesday, March 03, 2009

Unrecognized selector sent to instance

As you may or may not know, I do iPhone/Cocoa touch now...

While playing around with something this evening I stumbled across something I thought I'd share:

I received the following error in my Xcode console: "EXC_BAD_INSTRUCTION". More specifically the following was the message: "unrecognized selector sent to instance 0x52d960"...

After looking for some answers in my code and debugging through it, I came across this. When you build in Xcode by using cmd+B you apparently don't build (rebuild that is) the entire solution, but only the classes changed since last build. In my case the above error arose because the class I was working on, "A", called a method on another class "B" further calling a method on a class "C" that had changed signature. "A" was compiled with no errors, and "C" too. But "B" wasn't, and the erroneous method call wasn't caught by the compiler... I did a clean and then a build againg and the coding error was caught.

Just a little something to remember when working with Xcode.

2 comments:

棗子 said...

變天了~~注意身體,別感冒囉!..................................................

tim said...

I know this is an older post, but I wanted to thank you for posting your findings. I've been working on an app with quite a few dependencies, and just today (after a year of development), I started getting this non-stop. It was so bad in fact that I was thinking about scrapping the whole thing. Then, after reading your post, I cleaned my targets and I'm back in business.