参见英文答案 >
Swift 2 migration saveContext() in appDelegate2
我最近更新了Xcode到新的7.0测试版.
我最近更新了Xcode到新的7.0测试版.
我和助理进行了迁移,但还有一些问题.
- func saveContext () {
- if let moc = self.managedObjectContext {
- var error: NSError? = nil
- if moc.hasChanges && !moc.save() {
- NSLog("Unresolved error \(error),\(error!.userInfo)")
- abort()
- }
- }
- }
第4行有4个问题:
第一个是:
Binary operator ‘&&’ cannot be applied to two Bool operands
第二个是:
Call can throw,but it is not marked with ‘try’ and the error is not handled
有人可以帮帮我吗?
这是一些应该做的伎俩的代码.请记住先尝试抛出声明并抓住它们.
- func saveContext () {
- if let moc = self.managedObjectContext {
- if moc.hasChanges {
- do {
- try moc.save()
- } catch {
- NSLog("Unresolved error \(error)")
- abort()
- }
- }
- }
- }