Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if NSString is empty

What is the best was to determine if an NSString is empty? Right now I am using the following:

if (string == nil || [string isEqualToString:@""]) { // do something }

Thanks for any advice.

like image 397
Mark S. Avatar asked May 09 '10 13:05

Mark S.


People also ask

What is NSString?

A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.


1 Answers

if ([string length] == 0) {
    // do something
}

If the string is nil, then the message to nil will return zero, and all will still be well.

like image 87
John Calsbeek Avatar answered Oct 26 '22 23:10

John Calsbeek