我有CoreData
的应用。一切正常,直到我今天使用此guide中列出的说明将Google Analytics
添加到应用中。
我现在看到CoreData
中的AppDelegate
方法出错了:
错误是:
'ErrorType' is not convertible to 'NSError'; did you mean to use 'as!' to force downcast?
我尝试将其更改为as!
,甚至在没有运气的情况下删除as NSError
。
任何人都知道发生了什么?
更新
我找到了罪魁祸首,但仍然无法弄清楚它为什么会崩溃。使用Google Analytics设置项目时,指南会要求您将以下代码添加到每个视图控制器中的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])
导致构建失败,并显示上面显示的错误。
答案 0 :(得分:0)
例如
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()
}