Open Xcode and create a new project with the shortcut ⇧⌘N. Choose the Single View App template, click Next, and type in the product name IntoTheWild. Select SwiftUI for the user interface, click Next, and click Create.
In the app we’re going to build, we’ll register a region and the app will execute some code when the device enters or exits that region. Those events won’t be visible in the user interface. We want to be able to check if the events actually happen and if the app does what it should. To achieve that, add the logging package we built in Appendix 1, Debugging on the Go, to the project as described in Creating the Xcode Project . You can find the package at https://github.com/dasdom/LogStore2.git. After you’ve added the package to the Xcode project, open SceneDelegate.swift and import LogStore below the existing import statements.
| import UIKit |
| import SwiftUI |
| import LogStore |
Then add the highlighted lines in the following code:
| class SceneDelegate: UIResponder, UIWindowSceneDelegate { |
| |
| var window: UIWindow? |
» | var trigger: LogTrigger? |
| |
| func scene(_ scene: UIScene, |
| willConnectTo session: UISceneSession, |
| options connectionOptions: UIScene.ConnectionOptions) { |
| |
| let contentView = ContentView() |
| |
| if let windowScene = scene as? UIWindowScene { |
| let window = UIWindow(windowScene: windowScene) |
| window.rootViewController = UIHostingController(rootView: contentView) |
| self.window = window |
| window.makeKeyAndVisible() |
| |
» | |
» | #if DEBUG |
» | trigger = LogTrigger(in: window) |
» | #endif |
| } |
| } |
| // ... |
| // other methods |
| // ... |
| } |
If the app is compiled using the debug scheme, we use the log trigger to activate the trigger gesture for our logging library.