Checking if textfields are empty Swift

前端 未结 6 1690
悲&欢浪女
悲&欢浪女 2020-12-09 07:05

I know there are tons of stack overflow pages out there that explain how to do this but everytime I take the code from here and put it in i get the same error and that error

6条回答
  •  我在风中等你
    2020-12-09 07:44

    Alternatively you can also use:

    Swift 3:

    if (textField.text.characters.count > 0) {
       print("text field not empty")
    } else {
       print("text field empty")
    }
    

    Swift 4.x and above:

    if (textField.text.count > 0) {
           print("text field not empty")
        } else {
           print("text field empty")
        }
    

提交回复
热议问题