Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting an error on my (first ever) CardGameViewController
    text
    copied!<p>I'm getting the error <code>incompatible pointer types assigning to Deck *__strong from PlayCards *</code></p> <p>And i'm not sure why is that. Its in the first method implemented (deck):</p> <pre><code>#import "CardGameViewController.h" #import "PlayingCards.h" @interface CardGameViewController () @property (weak, nonatomic) IBOutlet UILabel *cardLabel; @property (nonatomic) NSUInteger flipsCount; @property (strong, nonatomic) Deck *deck; @end @implementation CardGameViewController -(Deck *) deck { if (!_deck) _deck = [[PlayingCards alloc] init]; return _deck; } -(void) setFlipsCount:(NSUInteger)flipsCount { _flipsCount = flipsCount; self.cardLabel.text = [NSString stringWithFormat:@"Flips:%d", self.flipsCount]; } - (IBAction)flipCard:(UIButton *)sender { sender.selected = !sender.isSelected; self.flipsCount++; } @end </code></pre> <p>This is the header file(nothing going on here):</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; //#import "Card.h" //#import "Deck.h" //#import "PlayingCards.h" @interface CardGameViewController : UIViewController @end </code></pre> <p>And the PlayingCard class inheriting from Deck class..</p> <p>this is the PlayingCards.m</p> <pre><code>#import "PlayingCards.h" @implementation PlayingCards @synthesize suit = _suit; //modifying the contents getter so it will return array with the ranks and rank+suit -(NSString *) contents { NSArray *cardsRank = [PlayingCards rankStrings]; return [cardsRank[self.rank] stringByAppendingString:self.suit]; } //creating a method to make sure we get validated suits +(NSArray *) validSuit { return @[@"♠",@"♣",@"♥",@"♦"]; } //creating calss method to validate the rank +(NSArray *) rankStrings { return @[@"?",@"A",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"J",@"Q",@"K"]; } //creating a new setter for suit to make sure we get the valitated suits, uding the validateSuit method -(void) setSuit:(NSString *)suit { if ([[PlayingCards validSuit] containsObject:suit]) { _suit = suit; } } //creating new getter for suit to make sure its not empty -(NSString *) suit { return _suit? _suit: @"?"; } //creating a class method to make sure when user set the rank he will will +(NSUInteger) maxRank { return [self rankStrings].count - 1; } //creating a new setter to the renk to make sure the rank is validates -(void) setRank:(NSUInteger)rank { if (rank &lt;= [PlayingCards maxRank]) { _rank = rank; } } @end </code></pre> <p>PlayingCards.h</p> <pre><code>#import "Card.h" #import "Deck.h" @interface PlayingCards : Card @property (strong, nonatomic) NSString *suit; @property (nonatomic) NSUInteger rank; +(NSArray *) validSuit; +(NSUInteger) maxRank; @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload