2017-03-02 1 views
0

Je migration mon code Swift de la version 2 à 3. Dans mon AppDelegate.swift j'ai la méthode suivante en cours d'exécution:référence à un membre Ambigu « SUBSCRIPT » dans 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 
} 

Je reçois le erreur suivante:

Ambiguous reference to member 'subscript'

Comment puis-je résoudre ce problème?

+0

Habituellement, il est parce que vous avez fait quelque chose de '[somethingelse]', mais vous n'avez pas précisé au compilateur que 'something' peut utiliser '[]' (indice). En outre, votre méthode n'est pas Swift 3: Vérifiez là: https://developer.apple.com/reference/uikit/uiapplicationdelegate/1622921-application pour le "compatible Swift3". – Larme

Répondre

0

Conformément aux recommandations @Larme je résolu le problème en changeant la signature de la méthode à:

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 
}