amstrudy amstrudy - 1 year ago 114
Objective-C Question

Receiver type error Obj-C

I'm brand new to Objective C and I'm trying to make a Hangman game. I realize my methods probably aren't the most efficient, but hey I'm learning so that's ok. Basically, each time a letter is entered I'm checking to see if there are any empty spaces left so I can display the "You won!" image. I keep getting two errors:

Receiver type 'char' is not 'id' or interface pointer , consider casting it to 'id'

Thread 1: EXC_BAD_ACCESS (code=1, address=0x63)

Any help is MUCH appreciated. Thanks in advance!

BOOL dash = YES;

for(int j = 0; j < self.correctWord.length; j++){

char temp = [self.correctWord characterAtIndex:j];

if([temp isEqual:@"-"])
dash = YES;


if(dash == YES)
self.hangmanImage.image = [UIImage imageNamed:@"wonimg"];

Answer Source

The thing with Objective-C is it's a 2-headed beast.

  1. There are objects, to which you send messages.
  2. There's plain C. No messages here, just operators and function calls.

Let's examine the error:

Receiver type 'char' is not 'id' or interface pointer , consider casting it to 'id'

A "receiver" is whatever receives a message. Making a generalization which is no longer accurate, a message is the square bracket stuff:

[receiver message]


[receiver messageArgument1:arg1 argument2:arg2]

An id type is Objective-C's notion of "any object".

So the error is trying to say that the receiver is a char which isn't an object. It's a plain C type. Here's the line with the problem:

if([temp isEqual:@"-"])

For a plain C type, test equality with the == operator:

if (temp == '-')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download