Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 876
Amit Kalra Avatar asked Aug 16 '16 04:08

Amit Kalra


People also ask

What is uialertcontroller in Swift?

UIAlertController is one of the most… | by Balaji Malliswamy | Swift India | Medium UIAlertController is one of the most basic component of the app development, because using the UIAlertController to get the feedback, confirmation, choose between the options from the user, also we do alerts.

How to declare an optional type in Swift?

If an optional contains a value in it, it returns value as Optional<Value>, if not it returns nil. Example 1: How to declare an optional in Swift? In the above program, we have initialized a optional type using ? and !. Both ways are valid to create an optional but there is one major difference which we will explore below.

How to handle optionals in Swift with if-LET statement?

The if-let statement also automatically unwraps the value and places the unwrapped value in temp constant. This technique has major advantage because you don't need to forcely unwrap the value although being certain an optional contains a value. 3. Guard statement You can use guard to handle optionals in Swift.

What is the argument to the sort method in Swift?

Because the sorting closure is passed as an argument to a method, Swift can infer the types of its parameters and the type of the value it returns. The sorted (by:) method is being called on an array of strings, so its argument must be a function of type (String, String) -> Bool.


2 Answers

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
}
like image 136
Naftali Beder Avatar answered Oct 25 '22 23:10

Naftali Beder


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

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

    ...

}
like image 38
quemeful Avatar answered Oct 25 '22 23:10

quemeful