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

What you learned

Project 29 was a serious game with a lot going on, not least the dynamically rendered buildings with destructible terrain, the scene transitions and the UIKit/SpriteKit integration.

And in project 30 we took our first steps outside of Xcode and into Instruments. I could write a whole book on Instruments, partly because it’s extremely powerful, but also because it’s extremely complicated. As per usual, I tried to cherrypick things so you can see useful, practical benefits from what I was teaching, and certainly you have the skills now to be able to diagnose and result a variety of performance problems on iOS.

Here are some of the things you learned in this milestone:

  • How to access the keychain using SwiftKeychainWrapper.
  • How to force the keyboard to disappear by calling resignFirstResponder() on a text view. (And remember: it also works on text fields.)
  • How to detect when your app is moving to the background by registering for the UIApplication.willResignActiveNotification notification.
  • How to use LAContext from the LocalAuthentication framework to require Touch ID authentication.
  • Using the stride() function to loop across a range of numbers using a specific increment, e.g. from 0 to 100 in tens.
  • Creating colors using the hue, saturation, and brightness. As I said, keeping the saturation and brightness constant while choosing different hues helps you create similar color palettes easily.
  • SpriteKit texture atlases. These are automatically made by Xcode if you place images into a folder with the .atlas extension, and are drawn significantly quicker than regular graphics.
  • Using usesPreciseCollisionDetection to make collisions work better with small, fast-moving physics bodies.
  • Transitioning between scenes with the presentScene() method and passing in a transition effect. We’ll be using this again in project 36, so you’ll have ample time to practice transitions.
  • Using the blend mode .clear to erase parts of an image. Once that was done, we just recalculated the pixel-perfect physics to get destructible terrain.
  • Adding dynamic shadows to views using layer.shadowRadius and other properties – and particularly how to use the layer.shadowPath property to save shadow calculation.
  • The importance of using dequeueReusableCell(withIdentifier:) so that iOS can re-use cells rather than continually creating new ones.
  • How the UIImage(named:) initializer has an automatic cache to help load common images. When you don’t need that, use the UIImage(contentsOfFile:) initializer instead.

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!

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!

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.