Checking if textfields are empty Swift

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

    The text property is an optional. So it can contains a String or nil.

    If you want to treat nil as an empty String then just write

    let isEmpty = (textField.text ?? "").isEmpty
    

提交回复
热议问题