2017-03-02 66 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 
}