Fix crash if batch update blocks are nil although method declaration allows nullable (#2599)

This commit is contained in:
Michael Schneider
2016-11-14 10:15:11 +09:00
committed by Adlai Holler
parent ae11fc755e
commit 44aa582ceb
4 changed files with 25 additions and 2 deletions
+3 -1
View File
@@ -653,7 +653,9 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
ASDisplayNodeAssertMainThread();
[_dataController beginUpdates];
updates();
if (updates) {
updates();
}
[_dataController endUpdatesAnimated:animated completion:completion];
}
+3 -1
View File
@@ -521,7 +521,9 @@ ASEnvironmentCollectionTableSetEnvironmentState(_environmentStateLock)
- (void)performBatchAnimated:(BOOL)animated updates:(void (^)())updates completion:(void (^)(BOOL))completion
{
[self.view beginUpdates];
updates();
if (updates) {
updates();
}
[self.view endUpdatesAnimated:animated completion:completion];
}
@@ -798,4 +798,14 @@
XCTAssertNotEqualObjects(oldHeader, newHeader);
}
- (void)testThatNilBatchUpdatesCanBeSubmitted
{
__block ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil];
__block ASCollectionNode *cn = testController.collectionNode;
// Passing nil blocks should not crash
[cn performBatchUpdates:nil completion:nil];
[cn performBatchAnimated:NO updates:nil completion:nil];
}
@end
+9
View File
@@ -705,6 +705,15 @@
}
}
- (void)testThatNilBatchUpdatesCanBeSubmitted
{
ASTableNode *node = [[ASTableNode alloc] initWithStyle:UITableViewStylePlain];
// Passing nil blocks should not crash
[node performBatchUpdates:nil completion:nil];
[node performBatchAnimated:NO updates:nil completion:nil];
}
@end
@implementation UITableView (Testing)