Evgeniy Kleban Evgeniy Kleban - 3 months ago 13
iOS Question

textView.text property is not nil when there is no text

I have a

, that the user may fill with text (and that text persist after app quit). I want to put a label on an empty view (when there is no text) to help user understand, that he may want to tap here and add text. My problem is, I can't figure out how to check whether
empty or not. That is what I have try:

if (self.descriptionTextView.text != nil){
isInformed = YES;
NSLog(@"here is text");
} else {
isInformed = NO;
NSLog(@"no text");

is a boolean value that I want to use to indicate where the
field is empty or not. Somehow,
"here is text"
always shows in the console, even when there is no text in view. Why is this happening? How to check it properly?

Any advice would be appreciated.


You should also check to see if the text is equal to @"" which is just an empty string.

You can solve for this by doing something like this:

if (self.descriptionTextView.text.length > 0){
    // Do stuff for text
}   else {
    // Do stuff for nil text or empty string