Easily testing if a string is nil or empty

February 27, 2013 in iOS Snippets

A very common idiom:

if ([string length]) {

// It's a string of at least one char, and is not null.


Works because calling a method on nil is not an error – just silently returns nil, which is also false.