![](/img/trans.png)
[英]Ambiguous reference to member 'subscript' when using FBSDKApplicationDelegate
[英]Ambiguous Reference To Member 'Subscript' when using UIApplicationShortcutItem
我正在嘗試將代碼遷移到Swift 3,並遇到有關嘗試處理3D Touch快捷方式的錯誤。
我收到以下錯誤
使用3D Touch快捷鍵執行Segue-成員“下標”的含糊不清
對於以下行
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:)
的方法標頭已更改為:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil)
符號UIApplicationLaunchOptionsShortcutItemKey
已替換為UIApplicationLaunchOptionsKey.shortcutItem
。
這可能是另一個問題,但是application(_:performActionFor:completionHandler:)
需要具有以下標頭:
func application(_ application: UIApplication,
performActionFor shortcutItem: UIApplicationShortcutItem,
completionHandler: @escaping (Bool) -> Void)
嘗試修復所有問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.