Search code examples
iosswift3appdelegateremote-notifications

Why ambiguous reference to member 'Subscript'?


This is my Swift 3 code:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    if let userInfo : Foundation.NSDictionary = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? Foundation.NSDictionary {
        self.setNavigationInfoFromPushNotification(userInfo: userInfo)
        navigateFromPushNotification()
    }
    ...
}

It results in a compile-time error that says:

Ambiguous reference to member 'Subscript'

Please can anyone help me with this?


Solution

  • The method signature has changed. See How to handle launch options in Swift 3 when a notification is tapped? Getting syntax problems.

    It is now:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { 
        if let userInfo = launchOptions?[.remoteNotification] as? NSDictionary {
            setNavigationInfoFromPushNotification(userInfo: userInfo)
            navigateFromPushNotification()
        }
        ...
    }