Solution to Assignment 1: Matchismo

Here is my solution to Assignment 1: Matchismo from the course “Developing iOS7 Apps for iPhone and iPad” (Fall 2013) by Stanford University.

There are just a few differences with the “official” solution as shown in the Lecture 3 video / slide .

  • Did not create a separate method createDeck to instantiate PlayingCardDeck (see line 13)
  • Instead of creating a new object Card, I just created a string to see if content is nil (see line 30, 31)
  • I moved self.flipCount++ inside the control statement that draws a random card (see line 35). Now a flip is counted only when you are looking at the card content/front. This way the maximum flip count equals to the total number of cards in deck, i.e. 52.
#import "CardGameViewController.h"
#import "PlayingCardDeck.h"

@interface CardGameViewController ()
@property (weak, nonatomic) IBOutlet UILabel *flipsLabel;
@property (nonatomic) int flipCount;
@property (strong, nonatomic) Deck *deck;

@implementation CardGameViewController

- (Deck *)deck {
    if (!_deck) _deck = [[PlayingCardDeck alloc] init];
    return _deck;

- (void)setFlipCount:(int)flipCount
    _flipCount = flipCount;
    self.flipsLabel.text = [NSString stringWithFormat:@"Flips: %d", self.flipCount];
    NSLog(@"flipCount changed to: %d", self.flipCount);

- (IBAction)touchCardButton:(UIButton *)sender {
    if ([sender.currentTitle length]) {
        [sender setBackgroundImage:[UIImage imageNamed:@"cardback"]
        [sender setTitle:@"" forState:UIControlStateNormal];
    } else {
        NSString *cardContent = [[self.deck drawRandomCard] contents];
        if (cardContent) {
            [sender setBackgroundImage:[UIImage imageNamed:@"cardfront"]
            [sender setTitle:cardContent forState:UIControlStateNormal];


1 thought on “Solution to Assignment 1: Matchismo Leave a comment

  1. Hi mysterious ObjectCoder,
    about method createDeck, your solution is the same as mine. But I think Paul Hegarty in this way he wanted to make the method more generally for the future development of the application. At least I think. I’m following the course of only a few days, so we’ll see.
    About second step, i think it’s good.
    Lastly, I consider the third step very very appropriate and logical. Congratulations!

    //Carlo Carlucci – Italy

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s