diff --git a/FirebaseDatabaseUI/FUIArray.m b/FirebaseDatabaseUI/FUIArray.m index 769aababd4b..34a7c11955a 100755 --- a/FirebaseDatabaseUI/FUIArray.m +++ b/FirebaseDatabaseUI/FUIArray.m @@ -161,7 +161,7 @@ - (void)invalidate { // Remove all values on invalidation. [self didUpdate]; - for (NSInteger i = 0; i < self.snapshots.count; i++) { + for (NSInteger i = 0; i < self.snapshots.count; /* no i++ since we modify the array instead*/ ) { FIRDataSnapshot *current = self.snapshots[i]; [self.snapshots removeObjectAtIndex:i]; @@ -269,7 +269,7 @@ - (id)objectAtIndexedSubscript:(NSUInteger)index { return [self snapshotAtIndex:index]; } -- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)index{ +- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)index { @throw [NSException exceptionWithName:@"FUIArraySetIndexWithSubscript" reason:@"Setting an object as FUIArray[i] is not supported." userInfo:nil]; diff --git a/FirebaseDatabaseUITests/FUIArrayTest.m b/FirebaseDatabaseUITests/FUIArrayTest.m index 93fa1d51c0b..a4797b2f657 100644 --- a/FirebaseDatabaseUITests/FUIArrayTest.m +++ b/FirebaseDatabaseUITests/FUIArrayTest.m @@ -476,4 +476,13 @@ - (void)testArraySendsMessagesAfterReceivingValueEvent { XCTAssert(ended == 1, @"expected array to end updates exactly once"); } +- (void)testRemovesAllElementsWhenInvalidated { + [self.observable populateWithCount:10]; + [self.firebaseArray invalidate]; + + XCTAssert(self.firebaseArray.count == 0, + @"Expected array to be empty after invalidation, instead got %ld elements", + self.firebaseArray.count); +} + @end