Binary operator '&&' cannot be applied to two Bool operands [duplicate]

丶灬走出姿态 提交于 2019-12-08 15:40:46

问题


I recently updated Xcode to the new 7.0 beta.

I did the migration with the assistant but there are a few more issues.

func saveContext () {
    if let moc = self.managedObjectContext {
        var error: NSError? = nil
        if moc.hasChanges && !moc.save() {
            NSLog("Unresolved error \(error), \(error!.userInfo)")
            abort()
        }
    }
}

On line 4 there are 4 issues: the first one is:

Binary operator '&&' cannot be applied to two Bool operands

the second one is:

Call can throw, but it is not marked with 'try' and the error is not handled

Can someone please help me?


回答1:


Here is some code that should do the trick. Remember to preceed throw statements with try and catch them.

func saveContext () {
    if let moc = self.managedObjectContext {
        if moc.hasChanges  {
            do {
                try moc.save()
            } catch {
                NSLog("Unresolved error \(error)")
                abort()
            }
        }
    }
}


来源:https://stackoverflow.com/questions/30822070/binary-operator-cannot-be-applied-to-two-bool-operands

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!