I am getting an error in my console:
2009-05-30 20:17:05.801 ChuckFacts[1029:20b] *** -[Joke isEqualToString:]: unrecognized selector sent to insta
Why is that error coming in?
Because you're sending isEqualToString:
to a Joke object, and your Joke objects don't respond to isEqualToString:
.
You're probably not intentionally sending that message to your Joke objects; instead, you're passing or returning Joke objects to something that is expecting NSString objects.
You say that jokes
is an “array of full of jokes”. Yet, in your code, you do this:
NSString *jokeText = [jokes objectAtIndex:indexPath.row]; UILabel *jokeTextLabel = (UILabel*) [cell viewWithTag:1]; jokeTextLabel.text = jokeText;
Going by the exception, I'm guessing that by “array full of jokes”, you meant “array of Joke objects”.
Putting a Joke object into an NSString *
variable does not turn the Joke object into an NSString. All you're doing is telling the compiler that the variable contains an NSString, then putting a Joke into it instead. I call this “lying to the compiler”.
The first step in fixing this is to remove the lie and restore truth in its place:
Joke *joke = [jokes objectAtIndex:indexPath.row];
If you compile immediately after doing this, you'll notice that the compiler has started giving you a warning a couple of lines later:
jokeTextLabel.text = jokeText;
warning: passing argument 1 of ‘setText:’ from distinct Objective-C type
It's right, of course. Jokes still aren't NSStrings. Now that you're honest about the variable's type, the compiler can catch this for you.
The actual fix comes when you ask the Joke object for its text (I assume that it has a property for this, and that the value of that property is an NSString) and give that to the jokeTextLabel.text
setter.
How can I determine what "0x52e2f0" is so it would be easier to find the problem next time?
In Xcode's Breakpoints window, set a breakpoint on objc_exception_throw
. Then run your program. When the exception happens, the debugger will stop your program, and the Debugger window will open. Then, type po 0x52e2f0
into the Debugger Console. (po
stands for “print object”.)
This works for Mac apps; I'm assuming it'd also work for iPhone apps.