Getting "use undeclared identifier" when I add getter, why?

enter image description here

I am completing a Matchismo assignment from the Stanford website.

So far I have been following the slides exactly as they are.

In addition, this error appears only when I implement the last method, that is, the recipient. If I remove the getter, no problem.

Notes can be downloaded here: Stanford Course Website

thank

the code:

.m file:

    #import "playingCard.h"

    @implementation playingCard

    -(NSString *) contents
    {
        NSArray *rankStrings = @[@"?",@"A",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"J",@"Q",@"K"];
    return [rankStrings[self.rank] stringByAppendingString:self.suit];

}

-(void) setSuit:(NSString *) suit
{
    if([@[@"♣︎",@"♥︎",@"♦︎",@"♠︎"] containsObject:suit])
    {
         _suit = suit;
    }
}



- (NSString *)isSuit
{
    return _suit ? _suit : @"?";
}

@end

.h file:

#import "card.h"

@interface playingCard : card


@property(strong, nonatomic, getter=isSuit) NSString *suit;
@property(nonatomic) NSUInteger rank;


@end
+4
source share
2 answers

Solution slide

Adding one line does the trick!

@synthesize suit = _suit;
+6
source

ALT, the moment ... you are mistaken for something.

You install @property, therefore it is suit auto-synthesized on _suit.

getter isSuit . , isSomething BOOL " " . :

@property(strong, nonatomic) NSString *suit;

, var , getter :

- (NSString *)suit
{
    return _suit ? _suit : @"?";
}

, .

!

-1

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


All Articles