So after much Googling and searching Swift forums, I'm coming up dry here.
What is the recommended approach to using class-bound delegates that have no SwiftUI counterpart (yet)?
Case in point: UIGuidedAccessRestrictionDelegate, where I may have typically added this as a conformance in an extension on AppDelegate.
@UIApplicationMain
class AppDelegate { ... }
extension AppDelegate: UIGuidedAccessRestrictionDelegate { ... }
However, SwiftUI apps are structs.
@main
struct MyApp: App { ... }
extension MyApp: UIGuidedAccessRestrictionDelegate { ... }
// error: Non-class type 'MyApp' cannot conform to class protocol 'NSObjectProtocol'
Apple's documentation mentions that this protocol must be adopted by the AppDelegate class. So this seems like a no-go for SwiftUI?
Are fringe feature-sets like Guided Access parameters being added to SwiftUI at some point in future?
cukr
2
Hi! These forums are about the Swift language, so questions about the SwiftUI private apple framework are kinda offtopic. In the future, try asking at SwiftUI | Apple Developer Forums
As for how to use UIApplicationDelegate in SwiftUI app, there is UIApplicationDelegateAdaptor property wrapper you can use
@main
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
...
}
class AppDelegate: NSObject, UIApplicationDelegate, UIGuidedAccessRestrictionDelegate {
...
}
1 Like
Brilliant, thank you.
I was headed to the Apple dev forums initially but came here in a brainfart thinking this would be a more appropriate place. This thread can be deleted if desired.
Lantua
4
IMO, it is swiftier to move the type of the delegate to the back:
@UIApplicationDelegateAdaptor var appDelegate: AppDelegate
not that it matters much.
1 Like
cukr
5
Yeah 
I just copied a snipped from www.hackingwithswift.com without much thought