1

i have an NSMutableArray that gives this output in the debug area:

finalArray  (
        (
    )
)

Now i want an if else statement to do something if this is the output. I tryd this:

NSArray *emptyArray = @[];
if (finalArray == nil || finalArray == emptyArray)
{
    NSLog(@"foobar");
}

How can i check if my array is this output?

2
  • 1
    your array has an item and that item is empty Commented Apr 30, 2014 at 13:56
  • 1
    If you want to check if finalArray is empty use count. Because == compares pointers, finalArray == emptyArray statement will never be true if these objects doesn't point the same address Commented Apr 30, 2014 at 13:56

2 Answers 2

1

Your array consists of another item (probably also an array) which is empty.

To check for that, you can use:

if(finalArray.firstObject.count == 0)
{
    NSLog(@"It's empty!");
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help. I changed the code a to this: if([_finalArray.firstObject count] == 0) {}
0

You can count the items of the array with the following code:

if([emptyArray count] == 0) {
    NSLog(@"array is empty");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.