Permalink
Browse files

Build up a list of bindings to remove, then remove them, to avoid

modifications to the nested arrays while they are being iterated over.
  • Loading branch information...
1 parent 81b6687 commit e262c4bb90dd86f5e56705df105d658e6c38e866 @lukeredpath lukeredpath committed Jun 21, 2012
Showing with 10 additions and 4 deletions.
  1. +10 −4 Library/PTPusherChannel.m
@@ -143,15 +143,21 @@ - (void)removeBinding:(PTPusherEventBinding *)binding
- (void)removeAllBindings
{
- NSArray *allBindings = [[dispatcher.bindings allValues] copy];
+ NSMutableArray *bindingsToRemove = [NSMutableArray array];
- for (NSArray *bindings in allBindings) {
- for (PTPusherEventBinding *binding in bindings) {
+ // need to unpack the bindings from the nested arrays, so we can
+ // iterate over them safely whilst removing them from the dispatcher
+ for (NSArray *bindingsArray in [dispatcher.bindings allValues]) {
+ for (PTPusherEventBinding *binding in bindingsArray) {
if (![internalBindings containsObject:binding]) {
- [dispatcher removeBinding:binding];
+ [bindingsToRemove addObject:binding];
}
}
}
+
+ for (PTPusherEventBinding *binding in bindingsToRemove) {
+ [dispatcher removeBinding:binding];
+ }
}
#pragma mark - Dispatching events

0 comments on commit e262c4b

Please sign in to comment.