0

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?

Rob
  • 415,655
  • 72
  • 787
  • 1,044
Megha
  • 95
  • 1
  • 7
  • Yes, this code is in didFinishLaunchingWithOptions only. – Megha Dec 26 '16 at 09:57
  • 1
    Can you please also include your current method signature for `didFinishLaunchingWithOptions` ? – Keiwan Dec 26 '16 at 10:03
  • @Rob Or it might be this: http://stackoverflow.com/questions/40209234/how-to-handle-launch-options-in-swift-3-when-a-notification-is-tapped-getting-s – Keiwan Dec 26 '16 at 10:04
  • `launchOptions` seems to be `Any?` and must be casted to a dictionary. And in Swift do not annotate types the compiler can infer and do not use `NSDictionary` unless you have no choice (here you have). – vadian Dec 26 '16 at 10:14
  • Yes, correct. I changed the syntax for didFinishLaunchingWithOptions method. It is working well. Thankyou !! – Megha Dec 26 '16 at 10:20
  • From func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool – Megha Dec 26 '16 at 10:21
  • func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { – Megha Dec 26 '16 at 10:23
  • 1
    @Keiwan - Yep, you're right. This turned out to be a duplicate of http://stackoverflow.com/questions/40209234/how-to-handle-launch-options-in-swift-3-when-a-notification-is-tapped-getting-s. – Rob Dec 26 '16 at 18:50

1 Answers1

1

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()
    }
    ...
}
Community
  • 1
  • 1
Rob
  • 415,655
  • 72
  • 787
  • 1,044