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.

  • Grabbing the first frame of a video from UIImagePickerController?
  • flip animation in swift flips whole view not subviews
  • How to scale down a UIImage and make it crispy / sharp at the same time instead of blurry?
  • unable to receive callback from second view controller
  • Fading out any content which approaches edges of UIScollView
  • How to get call history from iphone?
  • 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
    

    2 Solutions Collect From Internet About “Getting “use of undeclared identifier”, when I add the getter, why?”

    Solution slide

    Adding one line does the trick!

    @synthesize suit = _suit;
    

    ALT, moment…you are mistaking something.

    You set a @property so suit is autosynthesized to _suit.

    Then, your getter isSuit is logically wrong. I mean that isSomething is used to receive a BOOL and have a “more readable” getter. You don’t need in this case to change the name of the getter, and could declare the property just with:

    @property(strong, nonatomic) NSString *suit;
    

    At this point you don’t need to synthesise anything because your var is already autosinthesized, and your getter method can be simply:

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

    It is important that you understand what you are doing.

    Enjoy!