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
@IBInspectable, as well as how to create a 3D card flip effect using the
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 https://github.com/twostraws/HackingWithSwift. 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.
SPONSOR Tired of wasting time debugging your Swift app? Instabug’s SDK is here to help you minimize your debugging time by providing you with complete device details, network logs, and reproduction steps with every bug report. All data is attached automatically. It only takes a line of code to setup. Get started for free.