swift - 对成员 "text"的模糊引用

标签 swift string compiler-errors iboutlet

我有两个IBOulets:

@IBOutlet weak var usernameTextField: UITextField!

@IBOutlet weak var passwordTextField: UITextField!

我想检查他们的文本字段是否为空。但是,当我调用 text.isBlank 方法时,编译器显示错误 "Ambiguous reference to member 'text'"

   if ChatManager.shared.isConnected() {
        ChatManager.shared.disconnect()
        usernameTextField.isHidden = false
        passwordTextField.isHidden = false

    } else {


        guard usernameTextField.text.isBlank == false,
            passwordTextField.text.isBlank == false else {
            return
        }

我还注意到 UITextfield 有 text : String?或文本(UITextRange):字符串?

最佳答案

试试这个

else {
    guard usernameTextField.text.isEmpty == false,
    passwordTextField.text.isEmpty == false else {
    return
}

关于swift - 对成员 "text"的模糊引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45407381/

相关文章:

c# - 内存中烧录System.String

string - R 是否相当于 Python 的 "repr"(或 Lisp 的 "prin1-to-string")?

java - 表示日历对象的最佳规范字符串?

delphi - Indy 10 编译失败并启用 FASTMM 编译器指令

c# - System.Array不包含添加的定义

ios - 如何比较数组与嵌套数组并打印匹配对,而不是匹配的值列表? (代码有助于说明)

ios - 为什么 SKSpriteNodes 只呈现部分?

C 中的编译器错误 C2440

swift - 由于信号 : Segmentation fault: 11 | Xcode 7. 2 命令失败

ios - 我如何指示从 SKScene 使用 UIKit 创建的 View ?