UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Wrap up

The app is finished, but really your work is about to begin: I've given you all the code you need, but it's down to you to provide some meaningful patter to convince your friends! See "Polishing your patter" below for some example patter to get you started, but first give the app a quick try to make sure it all works.

To get started, run the app on your phone, then run it on your Watch. Note that installing apps and launching apps are both quite slow on Apple Watch, so make sure you prepare ahead of time. Once the Watch app is running, remember that it will go to sleep in 70 seconds unless you stop it, and when the Watch sleeps you won't get any haptic taps. The easiest thing to do is very gently rotate the Digital Crown every 30 seconds or so, just to be sure.

So, the app is complete and you've learned all about CAGradientLayer, CAEmitterLayer, card flip effects, perform(), 3D Touch and more - good job! If you want to try taking the app further, try implementing the sessionWatchStateDidChange() method in ViewController.swift to detect when the Watch goes to sleep – if you make your phone play a brief but innocuous sound, it would alert you to wake your watch.

If you're looking for something more advanced, try adding a hidden button to the Watch user interface that enables "always win mode" – i.e., every card that gets tapped will be the star. Your patter can then be, "I promise it's not a trick, in fact I can even transfer my psychic power to you!" and watch as your friend suddenly finds the star every time.

And if you’re keen to delve more into watchOS development, I wrote a whole book teaching you how to make watchOS apps: Hacking with watchOS.

Polishing your patter

Patter is verbal misdirection: what you say to your friends to confuse them while they are trying to figure out the trick. At the very least, you should explain to your friend how the cards work: there are eight cards with different shapes on, but only one has a green star. Let your friend try finding the card by hand, to prove the set up is real. Lucky people will guess the star correctly; very lucky people will guess twice in a row; but it's almost impossible that someone will get the answer right three times in a row - that's where you come in!

The easiest way to get started with the trick is by putting your finger down over one card, then dragging it slowly over the other cards. Note: don't tap the cards, because that will turn one of them over. Instead, slide your finger over them as if you're feeling for – ahem – psychic vibrations.

When you've done the trick correctly once or twice, your doubting friend will almost certainly think that there's some secret signal on the screen that is alerting you to the correct card, or perhaps you're performing some sort of gesture on the screen that triggers the star. In this situation, up the ante: tell them you can do the trick without even seeing the screen. In fact, you can do it without even touching the screen - they can do all the touching for you.

This works in just the same way, except now your friend is the one stroking their finger across the screen. Just wait for your Watch to tap your wrist, then say something like "go back to that card - I felt something there..."

Remember, misdirection is key. So, don't tap the right answer as soon as your phone vibrates. Say something like "hmm... this card feels really warm... let me try some others first." Or go to one of the cards nearby and say "this card feels warm, but not as warm as the previous one..."

Finally, once you've fooled everyone and had your fun, let them in on the joke - after all, if you can't have fun, why bother?

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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

Share your success!

One of the most effective motivators of success is sharing your progress with other people – when you tell folks what you're doing and what you've learned, it encourages you to come back for more, which in turn will help you reach your app development goals faster.

So, now that you've done all the hard work it's time to share your success: tell folks that you've completed this project, either by clicking the button below to start composing a tweet, or by writing your own message from scratch. This will definitely encourage you to keep learning, but it will also help other folks discover my work – thank you!

 

BUY OUR BOOKS
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: 5.0/5

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.