UIApplicationLaunchOptionsShortcutItemKey not there in Swift 3?
Asked Answered
C

3

7

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
Contaminant answered 16/8, 2016 at 4:36 Comment(5)
Try using guard : #33690433Archive
no luck :( same errorContaminant
So you're still getting the ambiguous reference to member subscript error? Your code looks correct as shown, so it might have something to do with the enclosing function. It's also possible you need to include the block if #available(iOS 9.0, *) {} around your shortcut code. More information/context would be helpful. :)Doloritas
So I just realized you're not unwrapping launchOptions, meaning it's still of Optional type when you try to use it. You can't pull values from an Optional dictionary, because it's not technically a dictionary. That's likely the issue. I've updated my answer to reflect this, and included the enclosing function as well. Let me know if it works!Doloritas
this still isn't working with Xcode 8 GMProtect
D
7

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
}
Doloritas answered 16/8, 2016 at 17:58 Comment(3)
If this is in application(_:willFinishLaunchingWithOptions:), then the launchOptions dictionary is already known to have key type UIApplicationLaunchOptionsKey. So you can just use launchOptions[.shortcutItem].Phagocytosis
Can you update your question to include the code and the function it's inside? (Ideally, please paste it as inline code, not as a screenshot.)Doloritas
My problem was the migration tool who missed changing the launchOptions type. So basically check the UIApplicationDelegate for the correct method interface. Should be launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil.Landed
P
1

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

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

    ...

}
Protect answered 12/9, 2016 at 11:44 Comment(0)
E
0

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 {
        }
    }
Evita answered 22/9, 2016 at 9:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.