Checking if textfields are empty Swift

前端 未结 6 1688
悲&欢浪女
悲&欢浪女 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:37

    It was this check that helped me since it was necessary for me to send a request to the API, and it was necessary to send nill instead of "" if the textField is without text.

    textField.text!.count > 0  ? textField.text : nil
    

    Alternatively, you can check this way (but this option did not fit me):

    if textField.text != nil {
    
    } else {
    
    }
    

提交回复
热议问题