How do I test if a string is empty in Objective-C?

Jamey McElveen picture Jamey McElveen · May 22, 2009 · Viewed 275k times · Source

How do I test if an NSString is empty in Objective-C?

Answer

Marc Charbonneau picture Marc Charbonneau · May 22, 2009

You can check if [string length] == 0. This will check if it's a valid but empty string (@"") as well as if it's nil, since calling length on nil will also return 0.