for(UIView *view in [_scrollView subviews]) {
NSMutableArray *_mutableArray = [_array mutableCopy];
[_mutableArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"guid like %@",view.object.guid]];
if([_mutableArray count] != 0) {
//object is already on screen we need to update it
[view setObject:(Object*)[_mutableArray objectAtIndex:0]];
}
else {
//object not on screen add it
_mutableArray = [_array mutableCopy];
[_mutableArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"guid not like %@",view.object.guid]];
UIView *newView = [[UIView alloc] initWithObject:(Object*)[_mutableArray objectAtIndex:0]];
[_scrollView addSubview:newView];
}
}
As you can see this method updates the objects that are on screen and if an object is not on screen it is created and added to the scrollView subview hierarchy. Now my concern is that I'm modifying the scrollView subviews hierarchy while enumerating it. Will this crash my app eventually?
If yes, how can I modify the above code to be safe and achieve the same functionality?
Thanks!