Hi all,
i want to check if my array is empty or null, and on base of which i want to create a condition for example.
if(array == EMPTY){
//do something
}
i hope i'm clear what i am asking, just need to check if my array is empty?
regards
Hi all,
i want to check if my array is empty or null, and on base of which i want to create a condition for example.
if(array == EMPTY){
//do something
}
i hope i'm clear what i am asking, just need to check if my array is empty?
regards
if (!array || !array.count){
...
}
That checks if array is not nil, and if not - check if it is not empty.
Just to be really verbose :)
if (array == nil || array.count == 0)
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.