Amit Nivedan Kalra Amit Nivedan Kalra - 3 months ago 59
Swift Question

UIApplicationLaunchOptionsShortcutItemKey not there in Swift 3?

Recently in Xcode 8 beta 6, 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

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
}