简体   繁体   English

使用UIApplicationShortcutItem时对成员“下标”的引用不明确

[英]Ambiguous Reference To Member 'Subscript' when using UIApplicationShortcutItem

I am trying to migrate my code to Swift 3, and came across an error regarding trying to handle 3D Touch shortcuts.. 我正在尝试将代码迁移到Swift 3,并遇到有关尝试处理3D Touch快捷方式的错误。

I get the following error 我收到以下错误

Performing segue using 3D Touch Shortcut - Ambiguous Reference To Member 'Subscript' 使用3D Touch快捷键执行Segue-成员“下标”的含糊不清

For the following line 对于以下行

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

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


}

I am not sure why I am getting this, does anyone else know ? 我不确定为什么要得到这个,其他人知道吗?

Here's how I am handling the shortcuts 这是我处理快捷方式的方式

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

The method header of application(_:didFinishLaunchingWithOptions:) has changed to: application(_:didFinishLaunchingWithOptions:)的方法标头已更改为:

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

The symbol UIApplicationLaunchOptionsShortcutItemKey has been replaced with UIApplicationLaunchOptionsKey.shortcutItem . 符号UIApplicationLaunchOptionsShortcutItemKey已替换为UIApplicationLaunchOptionsKey.shortcutItem

And this may be another issue, but application(_:performActionFor:completionHandler:) needs to have this header: 这可能是另一个问题,但是application(_:performActionFor:completionHandler:)需要具有以下标头:

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

Try fixing all of them. 尝试修复所有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM