2017-03-02 70 views
0
“下标”

我是从2版本迁移我的雨燕代码3.在我的AppDelegate.swift我已经正在实施以下方法:暧昧参考成员的AppDelegate

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'

我该如何解决这个问题?

+0

通常是因为你做了'东西[somethingelse]',但你没有指定编译器'something'可以使用'[]'(下标)。另外,你的方法不是Swift 3:请在这里检查:https://developer.apple.com/reference/uikit/uiapplicationdelegate/1622921-application“Swift3 compliant one”。 – Larme

回答

0

继@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 
}