gpt4 book ai didi

ios - 将 Google Analytics 添加到项目后 CoreData 方法出错

转载 作者:搜寻专家 更新时间:2023-11-01 05:37:55 24 4
gpt4 key购买 nike

我有一个带有 CoreData 的应用程序。在我今天使用此 guide 中概述的说明将 Google Analytics 添加到应用程序之前,一切都运行良好.

我现在在 AppDelegateCoreData 方法中看到一个错误:

enter image description here

错误是:

'ErrorType' is not convertible to 'NSError'; did you mean to use 'as!' to force downcast?

我试过将其更改为 as! 甚至删除 as NSError 但没有成功。

有人知道这是怎么回事吗?

更新:

我找到了罪魁祸首,但仍未弄清楚它崩溃的原因。使用 Google Analytics 设置项目时,指南会要求您将以下代码添加到每个 View Controller 中的 viewWillAppear 方法:

    let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: "name_of_controller")

let builder = GAIDictionaryBuilder.createScreenView()
tracker.send(builder.build() as [NSObject : AnyObject])

最后一行 tracker.send(builder.build() as [NSObject : AnyObject]) 导致构建失败并出现如上所示的错误。

最佳答案

例子

catch var error1 as NSError {
error = error1
coordinator = nil
// Report any error we got.
var dict = [String: AnyObject]()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
dict[NSUnderlyingErrorKey] = error
error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(error), \(error!.userInfo)")
abort()
} catch {
fatalError()
}

关于ios - 将 Google Analytics 添加到项目后 CoreData 方法出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34648275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com