Obj-C: Check for Empty Array
10,452
Solution 1
if([nsma count] == 0)
{
NSLog(@"nsma is empty");
}
Solution 2
check like this
if([array count]==0)
{
NSLog(@"Empty");
}
else
{
NSLog(@"not Empty");
}
Author by
Baub
Updated on June 26, 2022Comments
-
Baub almost 2 years
How do you check if an array is empty? (for the record, I looked at similar questions but didn't find the one with this exact problem).
I have a
NSMutableArray
(let's call itnsma
)that I need to check if empty. If I doNSLog(@"nsma: %@",nsma);
it logsnsma: ( )
, but if I doNSLog(@"nsma count:%@",nsma);
it logsnsma: (null)
. I need to check if it is empty, but my if statement that does that isn't working for some reason:if (nsma == nil) { NSLog(@"nsma is empty"); }
Does anyone know what is going on?
Thanks for the help in advance.