'AnyObject'与'[NSObject:AnyObject]'不同

时间:2014-09-08 14:18:39

标签: ios swift parse-platform

我在AppDelegate.swift文件中发现此错误,它出现在AppDidFinishLaunchingWithOptions函数中。它正在提高来自Parse框架的一行代码的错误。

PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)

错误出现在launchOptions参数上。我将发布整个函数以表明它应该是正确的。此外,当我注释掉代码行时,错误消失了,但我仍然真的希望能够使用该功能并跟踪分析。这是整个功能:

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
}

我似乎无法找到与此错误相关的任何内容。如果有人有一些见解我会非常感激!

2 个答案:

答案 0 :(得分:2)

自Xcode 6 beta 7起,当您想要致电application:didFinishLaunchingWithOptions:时,您必须更换:

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

使用以下代码:

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

此方法的最后一个参数不再是NSDictionary,而是类型为[NSObject: AnyObject]?的词典。因此,您必须更新代码(包括trackAppOpenedWithLaunchOptions:参数类型)。

答案 1 :(得分:1)

launchOptions参数应声明为NSDictionary!而不是AnyObject!

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