Search code examples
swiftswift3xcode83dtouchxcode8-beta6

UIApplicationLaunchOptionsShortcutItemKey not there in Swift 3?


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

Solution

  • 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
    }