views:

63

answers:

3

I am trying to compile some code where I have a class called Card. It has a method called

-(void)setSuit: (NSString *)suit

It is an instance method, but when I say [Card setSuit:@"Diamonds"]

Xcode says: warning: "Card" may not respond to method +setSuit

And my program doesn't work. I think that Xcode thinks setSuit is a class method, as it says in the warning, so how do I tell it that I am talking about an instance method?

Or maybe that isn't the problem at all, I don't really know as I have never encountered this before.

+5  A: 

You're trying to send -setSuit: to the Card class. You probably want to send that message to an instance of Card, not the class.

NSResponder
+5  A: 

The problem is here:

[Card setSuit:@"Diamonds"]

If Card is the class, then the above line will try to call a method on the class, not an instance. You'll need to call a method on an instance instead, say:

Card *card = [[Card alloc] init];
[card setSuit:@"Diamonds"];
Douglas