使用 UIApplicationShortcutItem 时对成员 'Subscript' 的引用不明确

Ambiguous Reference To Member 'Subscript' when using UIApplicationShortcutItem

我正在尝试将我的代码迁移到 Swift 3,但在尝试处理 3D Touch 快捷方式时遇到错误。

我收到以下错误

Performing segue using 3D Touch Shortcut - Ambiguous Reference To Member 'Subscript'

对于下一行

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: Any]?) -> Bool {

if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem {
        handleShortcutItem(shortcutItem)
}


}

我不确定为什么会收到这个,有其他人知道吗?

这是我处理快捷方式的方式

enum ShortcutItemType: String {
case First
case Second
case Third

init?(shortcutItem: UIApplicationShortcutItem) {
    guard let last = shortcutItem.type.components(separatedBy: ".").last else { return nil }
    self.init(rawValue: last)
}

var type: String {
    return Bundle.main.bundleIdentifier! + ".\(self.rawValue)"
}
}


fileprivate func handleShortcutItem(_ shortcutItem: UIApplicationShortcutItem) {

    if let rootViewController = window?.rootViewController, let shortcutItemType = ShortcutItemType(shortcutItem: shortcutItem) {

     let rootNavController = rootViewController.childViewControllers.first as! UINavigationController

        let viewController = rootNavController.childViewControllers[1]

        switch shortcutItemType {
        case .First:
            viewController.performSegue(withIdentifier: "firstSegue", sender: self)
            break
        case .Second:
            viewController.performSegue(withIdentifier: "secondSegue", sender: self)
            break
        case .Third:

            //Segue to view controller from first then perform another segue to a modal view. 

            viewController.performSegue(withIdentifier: "thirdSegue", sender: self)
            break
        }
    }
}


func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
    handleShortcutItem(shortcutItem)
}

application(_:didFinishLaunchingWithOptions:)的方法header已更改为:

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil)

符号 UIApplicationLaunchOptionsShortcutItemKey 已替换为 UIApplicationLaunchOptionsKey.shortcutItem

这可能是另一个问题,但是 application(_:performActionFor:completionHandler:) 需要这个 header:

func application(_ application: UIApplication,
                 performActionFor shortcutItem: UIApplicationShortcutItem,
                 completionHandler: @escaping (Bool) -> Void)

尝试修复所有问题。