Swift 3 migration tip: 'instance method ... nearly matches' warning
If during transition to Swift 3 in Xcode 8 you get a warning like this:
Instance method 'application(_:didFinishLaunchingWithOptions:)'
nearly matches optional requirement
'application(_:didFinishLaunchingWithOptions:)'
of protocol 'UIApplicationDelegate'
Don’t do any of the supplied fix-its. Instead, just type the same method again and you will see that the signature has changed:
// OLD
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
-> Bool {
self.window?.makeKeyAndVisible()
return true
}
// NEW
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil)
-> Bool {
self.window?.makeKeyAndVisible()
return true
}
Given fix-its only hide the issue, don’t really fix it.