From 79a6c662fe39737410789728acd4e5fa681c808d Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Mon, 3 Oct 2016 20:06:13 -0400 Subject: [PATCH] Handle nil node blocks gracefully in production (#2338) --- AsyncDisplayKit/ASCollectionView.mm | 2 +- AsyncDisplayKit/ASTableView.mm | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index 33fcb6de4d..2698391608 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -965,7 +965,7 @@ - (ASCellNodeBlock)dataController:(ASDataController *)dataController nodeBlockAt return ^{ __typeof__(self) strongSelf = weakSelf; - ASCellNode *node = block(); + ASCellNode *node = (block != nil ? block() : [[ASCellNode alloc] init]); [node enterHierarchyState:ASHierarchyStateRangeManaged]; if (node.interactionDelegate == nil) { node.interactionDelegate = strongSelf; diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index b255fbe103..fc879b593c 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -1140,10 +1140,11 @@ - (ASCellNodeBlock)dataController:(ASDataController *)dataController nodeBlockAt } ASCellNodeBlock block = [_asyncDataSource tableView:self nodeBlockForRowAtIndexPath:indexPath]; + ASDisplayNodeAssertNotNil(block, @"Invalid block, expected nonnull ASCellNodeBlock"); __weak __typeof__(self) weakSelf = self; ASCellNodeBlock configuredNodeBlock = ^{ __typeof__(self) strongSelf = weakSelf; - ASCellNode *node = block(); + ASCellNode *node = (block != nil ? block() : [[ASCellNode alloc] init]); [node enterHierarchyState:ASHierarchyStateRangeManaged]; if (node.interactionDelegate == nil) { node.interactionDelegate = strongSelf;