Last active
April 8, 2025 18:04
-
-
Save sebj/bae35d853be780434a894b62e21faaff to your computer and use it in GitHub Desktop.
Revisions
-
sebj revised this gist
Nov 18, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ See also: [`UIApplicationDelegate` documentation](https://developer.apple.com/do ```swift // AppDelegate.swift @main final class AppDelegate: NSObject, UIApplicationDelegate { func application( -
sebj revised this gist
Jan 10, 2023 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ ## Define an application delegate See also: [`UIApplicationDelegate` documentation](https://developer.apple.com/documentation/uikit/uiapplicationdelegate) ```swift // AppDelegate.swift @UIApplicationMain @@ -17,6 +19,8 @@ final class AppDelegate: NSObject, UIApplicationDelegate { ``` ## Define a scene delegate See also: [`UIWindowSceneDelegate` documentation](https://developer.apple.com/documentation/uikit/uiwindowscenedelegate) ```swift // SceneDelegate.swift final class SceneDelegate: NSObject, UIWindowSceneDelegate { -
sebj revised this gist
Jan 10, 2023 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,8 +35,7 @@ final class SceneDelegate: NSObject, UIWindowSceneDelegate { let window = UIWindow(windowScene: windowScene) // TODO: Do something with `window` let contentView = ContentView() // or whatever your root SwiftUI view is called window.rootViewController = UIHostingController(rootView: contentView) window.makeKeyAndVisible() -
sebj revised this gist
Jan 10, 2023 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ ## Define an application delegate ```swift // AppDelegate.swift @UIApplicationMain final class AppDelegate: NSObject, UIApplicationDelegate { @@ -17,6 +18,7 @@ final class AppDelegate: NSObject, UIApplicationDelegate { ## Define a scene delegate ```swift // SceneDelegate.swift final class SceneDelegate: NSObject, UIWindowSceneDelegate { var window: UIWindow? -
sebj revised this gist
Jan 10, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -45,7 +45,7 @@ final class SceneDelegate: NSObject, UIWindowSceneDelegate { ## Specify the scene delegate as part of the app's Info.plist file In a newly created SwiftUI project: 1. Click your project name in the left file navigator 2. Click the app target in the following screen 3. Click 'Info' -
sebj revised this gist
Jan 10, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ final class AppDelegate: NSObject, UIApplicationDelegate { configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions ) -> UISceneConfiguration { let sceneConfiguration = UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) sceneConfiguration.delegateClass = SceneDelegate.self return sceneConfiguration } -
sebj created this gist
Jan 10, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ ## Define an application delegate ```swift @UIApplicationMain final class AppDelegate: NSObject, UIApplicationDelegate { func application( _ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions ) -> UISceneConfiguration { let sceneConfiguration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role) sceneConfiguration.delegateClass = SceneDelegate.self return sceneConfiguration } } ``` ## Define a scene delegate ```swift final class SceneDelegate: NSObject, UIWindowSceneDelegate { var window: UIWindow? func scene( _ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions ) { guard let windowScene = scene as? UIWindowScene else { return } let window = UIWindow(windowScene: windowScene) // TODO: Do something with `window` let contentView = ContentView() window.rootViewController = UIHostingController(rootView: contentView) window.makeKeyAndVisible() self.window = window } } ``` ## Specify the scene delegate as part of the app's Info.plist file In a newly created project: 1. Click your project name in the left file navigator 2. Click the app target in the following screen 3. Click 'Info' 4. Expand 'Application Scene Manifest' 5. Add a row inside 'Application Scene Manifest' – Xcode will generate a `<Your-Target-Name>-Info.plist` file in the left file navigator 6. Right click on the generated plist file, and choose Open As → Source Code 7. Add the scene configuration below inside the `<dict>` for `UIApplicationSceneManifest` In a project with an existing Info.plist file: 1. Right click on the plist file in the left file navigator, and choose Open As → Source Code 2. Add the scene configuration below inside the `<dict>` for `UIApplicationSceneManifest` ``` <key>UISceneConfigurations</key> <dict> <key>UIWindowSceneSessionRoleApplication</key> <array> <dict> <key>UISceneConfigurationName</key> <string>Default Configuration</string> <key>UISceneDelegateClassName</key> <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string> </dict> </array> </dict> ```