Q:

Strange behavior with NSMutableArray

Here is a code from my application:
NSMutableArray *firstPhotoVoters = post.firstPhotoVoters;
NSMutableArray *secondPhotoVoters = post.secondPhotoVoters;

ALog(@"First voters: %@", firstPhotoVoters);
ALog(@"Second voters: %@", secondPhotoVoters);

for (Post* _post in posts) {
    if ([_post.objectId isEqualToString:post.objectId]) {
        [_post.firstPhotoVoters removeAllObjects];
        [_post.secondPhotoVoters removeAllObjects];

        ALog(@"Count: %d", firstPhotoVoters.count);

        ALog(@"Updated post: %@", _post);
    }
}

The two ALog statements (which is a macro for NSLog) dumps the array elements that exist in firstPhotoVoters and secondPhotoVoters arrays. However, inside the for loop the two arrays appear all empty. firstPhotoVoters.count is always zero. What am I missing here?
Thank you.

A:

You've just emptied the array and then you log it. It should be outside the if-statement.

