Dave Gallagher Dave Gallagher - 2 years ago 139
Swift Question

How to handle launchOptions: [NSObject: AnyObject]? in Swift?

In a Swift AppDelegate class, you get the following method:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// ...code...
return true

launchOptions: [NSObject: AnyObject]?
parameter is an optional. In Objective-C this is passed as an
. I'm looking to extract the
from it. Here's how it's done in Objective-C:

NSDictionary *remoteNotification = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];

if (remoteNotification)
// ...do stuff...

How would you go about doing that in Swift?

Answer Source

In Swift, you'd do it like this:

if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
    // ...do stuff...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download