doraemon doraemon - 1 year ago 476
iOS Question

application(_:didFinishLaunchingWithOptions:)' nearly matches optional , swift3, Xcode 8 beta 6

After installing Xcode 8 beta 6, I'm getting a warning saying:

Instance method 'application(_:didFinishLaunchingWithOptions:)' nearly matches optional requirement 'application(_:didFinishLaunchingWithOptions:)' of protocol 'UIApplicationDelegate'

in my App Delegate.

There are 2 suggested fixits to silence the warning:

  1. Mark the method as private

  2. Add @nonobjc to the method

Doing either silences the warning. But why does this need to be done?

Answer Source

This warning is due to the fact that the didFinishLaunchingWithOptions: parameter of the application(_:didFinishLaunchingWithOptions:) delegate method is now bridged to Swift as an [UIApplicationLaunchOptionsKey: Any]?, rather than an [NSObject : AnyObject]?.

Therefore you'll need to update your implementation to reflect this change:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // ...

Note that neither of Xcode's suggested fixes will actually fix the problem, they'll only conceal your implementation of application(_:didFinishLaunchingWithOptions:) from Objective-C – meaning that it'll never actually get called.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download