Memory Card Game Tutorial written in Swift

Introduction to Protocols

Xiomara Figueroa
xiomara.dev

--

We’re going to build a simple memory card game that I find very straightforward and fun to play. And hopefully we can learn a little bit about classes, and Swift’s protocols in the process.

Before jumping into the coding part, let’s look at how to play this game.

How to play Memory Card

Our memory card game has a grid of 4x4 cells. Initially, all cells are shown but their images are hidden. When you tap on a cell, it reveals the image behind it.

The player’s task is to find the matching cell. If the next cell they tap on contains the same image, then it’s a match and the two cells remain visible.

If the next cell does not contain the same image, then it’s a miss and both cells go back to the hidden state. The player continues until they find all matching cells.

Straightforward and fun!

Project Structure

In order to build a simple version of this game, we’re going to need the following components:

--

--