TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Setting up

Are you psychic? Of course not. But what if we could use our coding skills to make a game to fool your friends into thinking otherwise – while also learning some new techniques along the way?

In this project we're going to build a simple game that recreates the classic Zener test for extrasensory perception. Our game will show the user eight cards face down, and users need to tap the card that has a star on its flip side. Casual players will get it right 1 in 8 times, but you'll get it right every time. Magic!

Well, no. We'll be cheating, naturally, but even in this cheating I'm going to find new things to teach you. First, we're going to build a tiny watchOS app that silently taps your wrist when your finger moves over the star card. Then we're going to add 3D Touch support so that pressing hard on any card will automatically make it the star. Whichever technique you use is going to be enough to baffle your friends, although I hope you use your powers for good!

At the same time we'll also be learning about CAEmitterLayer, CAGradientLayer, @IBDesignable and @IBInspectable, as well as how to create a 3D card flip effect using the transition(with:) method.

I've left the Apple Watch and 3D Touch code until the end of the project, so at the very least you'll be able to work through the majority of the tutorial without needing special hardware. That being said, we'll be using one of Xcode's built-in iOS/watchOS templates to make the end result easier to reach.

Are you ready to take your first step into the Twilight Zone? Go ahead and launch Xcode, then create a new project. When Xcode asks you which template you want, please select watchOS then iOS App with WatchKit App. Set the target to be iPhone, the language to be Swift, then deselect Include Notification Scene. Finally, name it Project37 and click Next.

Once the project is created, please set it to support landscape left and right only; no portrait this time. You will also need to copy the image assets for this project into your project's asset catalog – you can find them all on GitHub at You'll also find a Content directory in that download; please add that to your project too, because it contains some music for later on.

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 3.0/5

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.