I am try to check textfield is blank or not and what I am trying is
if(EmailTextField.text.characters.count>0)
{
}
but I can't use relation operator on this count method. Why?
I am try to check textfield is blank or not and what I am trying is
if(EmailTextField.text.characters.count>0)
{
}
but I can't use relation operator on this count method. Why?
You can use the String
's isEmpty
property:
//if EmailTextField is a UITextField instance
if EmailTextField.text != nil && !EmailTextField.text!.isEmpty {
}
if let text = EmailTextField.text where !text.isEmpty {
}
By extension... To ensure that its not even take any blank spaces...
extension String {
var isBlank: Bool {
get {
let trimmed = stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
return trimmed.isEmpty
}
}
}
Usage:
if !EmailTextField.text!.isBlank{
//TextField is not blank
}