Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIApplicationLaunchOptionsKey not found

UIApplicationDelegate method - application(_:didFinishLaunchingWithOptions:) showing an error with Swift 4.2 (Xcode 10).

UIApplicationLaunchOptionsKey not found

What is replacement of UIApplicationLaunchOptionsKey in Swift 4.2?

enter image description here

like image 848
Krunal Avatar asked Jun 05 '18 12:06

Krunal


5 Answers

'UIApplicationLaunchOptionsKey' has been renamed to 'UIApplication.LaunchOptionsKey'. Replace 'UIApplicationLaunchOptionsKey' with 'UIApplication.LaunchOptionsKey'.

Click on error hint, will show you solution:

enter image description here

like image 172
indus Avatar answered Oct 29 '22 14:10

indus


func application(_ application: UIApplication, 
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

}
like image 41
Samir Avatar answered Oct 29 '22 12:10

Samir


Xcode would fix-it but UIApplicationLaunchOptionsKey is replaced by a nested type UIApplication.LaunchOptionsKey.

like image 35
OOPer Avatar answered Oct 29 '22 14:10

OOPer


It should be UIApplication.LaunchOptionsKey, Please find following apple documentation

like image 29
PPL Avatar answered Oct 29 '22 12:10

PPL


I have tried the below snippet of the code and worked for me.

func application(_ application: UIApplication, 
    didFinishLaunchingWithOptions launchOptions: [UIApplication: Any]? = nil) -> Bool {

}

Just provide UIApplication in launchOptions. Hopes it will work for you as well. :)

like image 29
Bhoopi Avatar answered Oct 29 '22 14:10

Bhoopi