二进制运算符“&&"不能应用于两个布尔操作数 [英] Binary operator '&&' cannot be applied to two Bool operands

查看:136
本文介绍了二进制运算符“&&"不能应用于两个布尔操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将Xcode更新为新的7.0 Beta.

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()
        }
    }
}

第4行有4个问题: 第一个是:

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

二进制运算符&&"不能应用于两个布尔操作数

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

第二个是:

呼叫可以抛出,但未标记为"try",并且未处理错误

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

有人可以帮我吗?

推荐答案

下面是一些可以解决问题的代码.切记在尝试引发语句之前先引发语句.

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()
            }
        }
    }
}

这篇关于二进制运算符“&&"不能应用于两个布尔操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆