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
▿ Optional<UIApplicationDelegate>
▿ some : <SwiftUI.AppDelegate: 0x282969760>
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
▿ Optional<UIApplicationDelegate>
▿ some : <SwiftUI.AppDelegate: 0x282969760>