0

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.

Marcy
  • 4,611
  • 2
  • 34
  • 52
  • 1
    Probably it's just type inferring. It doesn't matter where you specify the type because it's supposed to be the same. – Sulthan Jan 16 '23 at 17:00

1 Answers1

2

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.

Sulthan
  • 128,090
  • 22
  • 218
  • 270