Skip to content

Commit

Permalink
Do not call the willFinishLaunching delegate method in the Preview Case
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Jan 10, 2024
1 parent d7914fa commit ce737f8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sources/Spezi/Spezi/SpeziAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ open class SpeziAppDelegate: NSObject, UIApplicationDelegate, UISceneDelegate {
// swiftlint:disable:next discouraged_optional_collection
willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
spezi.willFinishLaunchingWithOptions(application, launchOptions: launchOptions ?? [:])
if !ProcessInfo.processInfo.isPreviewSimulator {
// If you are running an Xcode Preview and you have your global SwiftUI `App` defined with
// the `@UIApplicationDelegateAdaptor` property wrapper, it will still instantiate the App Delegate
// and call this willFinishLaunchingWithOptions delegate method. This results in an instantiation of Spezi
// and configuration of the respective modules. This might and will cause troubles with Modules that
// are only meant to be instantiated once. Therefore, we skip execution of this if running inside the PreviewSimulator.
// This is also not a problem, as there is no way to set up an application delegate within a Xcode preview.
spezi.willFinishLaunchingWithOptions(application, launchOptions: launchOptions ?? [:])
}
return true
}

Expand Down

0 comments on commit ce737f8

Please sign in to comment.