Why can Xcode read an instance method as a class method?

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

-(void)setSuit: (NSString *)suit

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

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

And my program is not working. I think Xcode thinks that setSuit is a class method, as the warning says, so how can I say that I'm talking about an instance method?

Or maybe this is not a problem at all, I don’t know how I have never met before.

+3
source share
2 answers

The problem is here:

[Card setSuit:@"Diamonds"]

Card - , , . , :

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

-setSuit: Card. , Card, .

+5

Source: https://habr.com/ru/post/1764334/


All Articles