文字前的快速感叹号 [英] Swift exclamation mark before a text

查看:172
本文介绍了文字前的快速感叹号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理的本教程说,我必须禁用保存"按钮,直到文本字段中包含一些值为止. 这是代码:

This tutorial I am currently working on says I have to disable the Save Button until the text field has some value in it. Here is the code:

saveButton.isEnabled = !text.isEmpty

text.isEmpty之前的感叹号是否表示启用了保存按钮,否则文本不是空的,与!=等于不等于的方式相同吗? 我知道感叹号表示强制展开,但是我认为您在文本后面加上了感叹号. 顺便说一句(我已经对其进行了测试,并且按照教程中的说明进行了工作)

Does the exclamation mark before text.isEmpty mean that the save button is enabled is the text is not empty same way that != mean not equal to? I know exclamation mark means force unwrap, but I thought you put the exclamation mark after the text. BTW(I have tested it and it works as the tutorial says so)

推荐答案

text.isEmpty之前的惊叹号称为

The exclamation mark before text.isEmpty called Logical NOT operator, it inverts the boolean value.

saveButton.isEnabled = !text.isEmpty

表示如果text为空,则>不会启用,反之亦然.

means that if text is empty, the saveButton will not be enabled, and vice versa.

为了更清楚一点,如果我们尝试将其翻译为if语句,则应为:

To make it more clear, if we tried to translate it as an if-statement, it should be as:

if text.isEmpty {
    saveButton.isEnabled = false
} else {
   saveButton.isEnabled = true
}

这篇关于文字前的快速感叹号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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