stevengbu stevengbu - 4 months ago 212
Swift Question

Ambiguous reference to member 'subscript' when using FBSDKApplicationDelegate

I have updated swift 3 and I found many errors. This is one of them :

Ambiguous reference to member 'subscript'

For the following line

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as? String, annotation: options["UIApplicationOpenURLOptionsAnnotationKey"] as? String)

return true

I am not sure why I am getting this, does anyone else know ?

It works well in previous version 7.3.1 swift 2.


The type of the options dictionary has changed from [String: AnyObject] to [UIApplicationOpenURLOptionsKey : Any] this means you should subscript with UIApplicationOpenURLOptionsKey instead of a String like you're doing now.

Try this:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    guard let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
        let annotation = options[UIApplicationOpenURLOptionsKey.annotation] else {
            return false

    return FBSDKApplicationDelegate.sharedInstance().application(app, open: url,
                                                                 sourceApplication: sourceApplication,
                                                                 annotation: annotation)


This code extracts the keys you're looking for from the options and passes them to the FBSDKApplicationDelegate. Note the usage of UIApplicationOpenURLOptionsKey.sourceApplication and UIApplicationOpenURLOptionsKey.annotation to access values in the options dictionary.