I need to know if an NSArray is empty or null using an if.
Code:
NSArray* array;
if( array == nil)
{
// Fazer algo
}
I need to know if an NSArray is empty or null using an if.
Code:
NSArray* array;
if( array == nil)
{
// Fazer algo
}
As in objective -c a message for nil
returns nil
, you can use the code below:
NSArray *array = [obtem o valor];
if ([array count]) {
// Nao é vazio nem nulo
}
If the array is nil
, then the result of [array count]
will also be nil
(which is considered "false" in if). If it is not nil
, then the count
method returns the number of elements. If it is zero, the if will not go either, since zero is also considered false.
Well, it was faster than I thought.
I used NULL instead of nil, thus:
NSArray* array;
if( array == NULL)
{
// Fazer algo
}