O'Reilly logo

Mastering iOS 11 Programming - Second Edition by Donny Wals

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating the login interface

Just like before, we'll implement the required code and set up the outlets we need before we implement the interface in the Interface Builder. Apple recommends that apps that make use of a CMMotionManager only use a single motion manager throughout their app. To make this manageable, and to follow the best practices for dependency injection, we will make AppDelegate responsible for injecting a motion manager into our view controller. You saw this approach before when we injected a managed object context into a view controller.

Add the following code to your AppDelegate's application(_:didFinishLaunchingWithOptions:) method:

if let viewController = window?.rootViewController as? ViewController {  viewController.motionManager ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required