简体   繁体   中英

'AnyObject' is not identical to '[NSObject : AnyObject]'

I am finding this error in my AppDelegate.swift file and it appears in the AppDidFinishLaunchingWithOptions function. It is raising the error on a line of code that is from the Parse framework.

PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)

The error is appearing on the launchOptions parameter. I will post the whole function to show that it should be correct. Also when I comment out the line of code the error disappears, but I still really want to be able to use the function and track the analytics. Here is the whole function:

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: AnyObject!) -> Bool
{
    // Override point for customization after app launches
    Parse.setApplicationId("removed on purpose", clientKey: "removed on purpose")
    PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
    PFFacebookUtils.initializeFacebook()

    return true
}

I can't seem to find anything that relates to this error. If anyone has some insight I would really appreciate it!

Since Xcode 6 beta 7, when you want to call application:didFinishLaunchingWithOptions: , you have to replace:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    /* ... */
}

with the following code:

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

The last parameter of this method is no more a NSDictionary but a Dictionary of type [NSObject: AnyObject]? . Therefore, you must update your code (including your trackAppOpenedWithLaunchOptions: parameter type).

The launchOptions parameter should be declared as NSDictionary! instead of AnyObject! :

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
    // ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM