ios - AppDelegate 中对成员 'subscript' 的引用不明确

标签 ios swift swift3 appdelegate

我正在将 Swift 代码从版本 2 迁移到版本 3。在我的 AppDelegate.swift 中,我实现了以下方法:

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

    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

    // error below this line
    if let notification = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [NSObject : AnyObject] {
    } else {}
    return true
}

我收到以下错误:

Ambiguous reference to member 'subscript'

如何解决这个问题?

最佳答案

按照@Larme的建议,我通过将方法签名更改为解决了这个问题:

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

    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

// error below this line
    if let notification = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [NSObject : AnyObject] {
    } else {}
    return true
}

关于ios - AppDelegate 中对成员 'subscript' 的引用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42557652/

相关文章:

ios - 如何在 iOS 7 中使用 AVSpeechSynthesizer 改变说话时的语速

ios - 如何在 Swift 中为所有 iOS 设备水平居中标签

swift - allHeaderFields 在查找键时不区分大小写

ios - 根据动态输入自动调整表格 View 中的单元格大小

ios - 从 uitableview 中的 uitextfield 获取值

ios - 在函数 cellForRowAt 中访问静态单元格的 detailTextLabel

ios - ionic (应用程序流): Please register custom URL scheme - scheme present in plist file

ios - 为什么我的 iOS 正则表达式不起作用?

ios - UICollectionView 中每个项目的不同行间距 - swift 3

ios - 在不同的 Collection View 之间拖放单元格