How to use UIApplicationDelegateAdaptor
With SwiftUI 2.0, UIApplicationDelegate
is a thing of the past… well, maybe not. While the new App
protocol and friends provide great, declarative abstractions over UIKit/AppKit app lifecycle APIs, their shortcomings may become evident when faced with complex scenarios - such as handling remote notifications, or handling shortcuts.
Fortunately, SwiftUI 2.0 provides us with a bridge between our two worlds:
/// A property wrapper that is used in `App` to provide a delegate from UIKit.
@available(iOS 14.0, tvOS 14.0, *)
@available(OSX, unavailable)
@available(watchOS, unavailable)
@propertyWrapper public struct UIApplicationDelegateAdaptor<DelegateType> : DynamicProperty where DelegateType : NSObject, DelegateType : UIApplicationDelegate {
/// The underlying delegate.
public var wrappedValue: DelegateType { get }
/// Creates an `UIApplicationDelegateAdaptor` using a UIKit
...