如何在Swift中获得Bool的相反值? [英] How can I get the opposite value of a Bool in Swift?

查看:1147
本文介绍了如何在Swift中获得Bool的相反值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的具体情况是我试图切换导航栏隐藏和显示。

My specific case is I am trying to toggle the nav bar hidden and showing.

    let navHidden = !self.navigationController?.navigationBarHidden
    self.navigationController?.setNavigationBarHidden(navHidden!, animated: true)

对我来说不像通常在Obj-C中那样。

Is not working for me like it normally would in Obj-C.

推荐答案

感叹号位于布尔值的错误一侧。你写它的方式表明布尔值可能是零。你想要!navHidden。

The exclamation point is on the wrong side of the boolean. The way you've written it would indicate that the boolean could be nil. You want !navHidden.

这篇关于如何在Swift中获得Bool的相反值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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