Post

Replies

Boosts

Views

Created

UIApplication.shared.delegate as? AppDelegate is nil
When I click button to get AppDelegate, it return nil. How can I get AppDelegate in click action ? ... @main struct GymantApp: App {    @UIApplicationDelegateAdaptor(AppDelegate.self) public var appDelegate    ... } ... Button Button("test button") {         if let appDelegate = UIApplication.shared.delegate as? AppDelegate {           ...         } else {           os_log(.debug, "appDelegate is nil")         }       } ... Po UIApplication.shared.delegate po UIApplication.shared.delegate ▿ OptionalUIApplicationDelegate  ▿ some : SwiftUI.AppDelegate: 0x282969760
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
1.5k
Mar ’21