Skip to content

Instantly share code, notes, and snippets.

@twissmueller
Last active December 10, 2020 06:59
Show Gist options
  • Save twissmueller/90bed7f22f3a760dc09e0cfe434f3ebd to your computer and use it in GitHub Desktop.
Save twissmueller/90bed7f22f3a760dc09e0cfe434f3ebd to your computer and use it in GitHub Desktop.
A template for an application based on SwiftUI
import SwiftUI
import os.log
@main
struct MyApp: App {
private let logger = Logger(subsystem: "bundleId", category: "classname")
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}
.onChange(of: scenePhase) { (newScenePhase) in
switch newScenePhase {
case .active:
logger.debug("Scene entered active phase")
case .inactive:
logger.debug("Scene entered inactive phase")
case .background:
logger.debug("Scene entered background phase")
@unknown default:
logger.debug("Scene entered an undetermined phase")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment