Aleksandar • Vacić

iOS bits and pieces

Swift 3 migration tip: 'instance method ... nearly matches' warning

If during transition to Swift 3 in Xcode 8 you get a warning like this:

1
2
3
4
 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 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.