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.
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"];
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With