How to check if array is null or empty?

Solution 1:

if (!array || !array.count){
  ...
}

That checks if array is not nil, and if not - check if it is not empty.

Solution 2:

if ([array count] == 0)

If the array is nil, it will be 0 as well, as nil maps to 0; therefore checking whether the array exists is unnecessary.

Also, you shouldn't use array.count as some suggested. It may -work-, but it's not a property, and will drive anyone who reads your code nuts if they know the difference between a property and a method.

UPDATE: Yes, I'm aware that years later, count is now officially a property.

Solution 3:

you can try like this

if ([array count] == 0)

Solution 4:

Best performance.

if (array.firstObject == nil)
{
    // The array is empty
}

The way to go with big arrays.

Solution 5:

Just to be really verbose :)

if (array == nil || array.count == 0)