NSMutableArray的奇怪行为

时间:2013-05-28 11:51:56

标签: objective-c

以下是我的应用程序中的代码:

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);
    }
}

两个ALog语句(NSLog的宏)转储firstPhotoVoters和secondPhotoVoters数组中存在的数组元素。但是,在for循环中,两个数组看起来都是空的。 firstPhotoVoters.count始终为零。我在这里缺少什么?

谢谢。

1 个答案:

答案 0 :(得分:0)

你刚刚清空了数组然后你就记录了它。它应该在if语句之外。

相关问题