UIApplicationLaunchOptionsShortcutItemKey not there in Swift 3?

3.5k Views Asked by At

Recently in Xcode 8 beta 6 (8S201h), this has become a problem.

 UIApplicationLaunchOptionsShortcutItemKey

Here's the error :

enter image description here

Anyone else having this issue?

var performShortcutDelegate = true
if let shortcutItem = launchOptions[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
    print("ok")
    self.shortcutItem = shortcutItem
    performShortcutDelegate = false
}
return performShortcutDelegate
3

There are 3 best solutions below

3
On BEST ANSWER

The constant has changed (see the documentation). You also need to unwrap launchOptions before using any values it contains.

Enclosing function is included for context.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    if let launchOptions = launchOptions {
        if #available(iOS 9.0, *) {
            if let shortcutItem = launchOptions[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
                print("Shortcut: \(shortcutItem)")
            }
        }
    }
    return true
}
0
On

Try this.. Its work for me using Xcode8 , swift3

    //Check for ShortCutItem
    if #available(iOS 9.0, *) {
        if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
        }
    }
0
On

The launchOptions Dictionary type has changed in the function parameters to [UIApplicationLaunchOptionsKey: AnyObject].

private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: AnyObject]?) -> Bool {

    ...

}