Objective c checking whether text field is empty

Simply checks for nil and if length of text length is greater than 0 - not empty

if (textField.text && textField.text.length > 0)
{
   /* not empty - do something */
}
else
{
   /* what ever */
}

Joshua has the right answer in the narrow case, but generally, you can't compare string objects using the == or != operators. You must use -isEqual: or -isEqualToString: This is because charlieImputSelf and @"" are actually pointers to objects. Although the two sequences of characters may be the same, they need not point at the same location in memory.


We already have inbuilt method that return boolean value that indicates whether the text-entry objects has any text or not.

// In Obj-C
if ([textField hasText]) {
        //*    Do Something you have text
    }else{
         /* what ever */
    }

// In Swift

if textField.hasText {
    //*    Do Something you have text
}else{
     /* what ever */
}