Home > Software design >  @UIApplicationDelegateAdaptor(AppDelegate.self)?
@UIApplicationDelegateAdaptor(AppDelegate.self)?

Time:01-17

When using SwiftUI's @UIApplicationDelegateAdaptor, many in the Swift community(SO, blogs, courses) register the app delegate class like this:

@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

Apple's documentation uses code similar to this example:

@UIApplicationDelegateAdaptor var appDelegate: AppDelegate

I've been using the latter with no problems that I've noticed. The latter seems more readable. Could someone explain the difference and when I should use one over the other? I think I'm not understanding something.

CodePudding user response:

The fully specified version would be:

@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate: AppDelegate

Since both types (variable type and propertyWrapper type) are the same, you can omit either of them and it will be inferred.

  • Related