我最近将 Xcode 更新到了新的 7.0 beta。
我使用助手进行了迁移,但还有一些问题。
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
有人可以帮我吗?
最佳答案
这里有一些代码可以解决这个问题。请记住在 throw 语句之前添加 try 并捕获它们。
func saveContext () {
if let moc = self.managedObjectContext {
if moc.hasChanges {
do {
try moc.save()
} catch {
NSLog("Unresolved error \(error)")
abort()
}
}
}
}
关于beta - 二元运算符 '&&' 不能应用于两个 Bool 操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30822070/