Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting “use of undeclared identifier”, when I add the getter, why?

enter image description here

I am doing the Matchismo assignment from the Stanford website.

So far I have followed the slides exactly the way they are.

Also, this error only shows up when I implement the last method i.e. the getter. If I remove the getter, there's no issue.

The notes can be downloaded from here: Stanford Course Website

Thanks

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
like image 543
CP3O Avatar asked Feb 13 '23 21:02

CP3O


1 Answers

Solution slide

Adding one line does the trick!

@synthesize suit = _suit;
like image 132
CP3O Avatar answered Feb 15 '23 11:02

CP3O