From e9e09d726c2dcfd6db69b2a94f5bb7717280231e Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Fri, 31 Mar 2017 14:57:53 -0700 Subject: [PATCH] Make -[IGListBindingSectionController object] Public Summary: Issue fixed: #572 I didn't add an entry into `CHANGELOG` since the entire component is new. I've been doing some proof-of-concepts for IGListBindingSectionController + AsyncDisplayKit in Pinterest and it's working like a charm! Closes https://github.com/Instagram/IGListKit/pull/602 Reviewed By: rnystrom Differential Revision: D4812758 Pulled By: jessesquires fbshipit-source-id: 9c23f32882cb99f6539ab45dec0e76a274c64370 --- Source/IGListBindingSectionController.h | 7 ++++++- Source/IGListBindingSectionController.m | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Source/IGListBindingSectionController.h b/Source/IGListBindingSectionController.h index 482fe348..f66ccc85 100644 --- a/Source/IGListBindingSectionController.h +++ b/Source/IGListBindingSectionController.h @@ -47,7 +47,7 @@ NS_ASSUME_NONNULL_BEGIN Only when `-diffIdentifier`s match is object equality compared, so you can assume the class is the same, and the instance has already been checked. */ -@interface IGListBindingSectionController : IGListSectionController +@interface IGListBindingSectionController<__covariant ObjectType : id> : IGListSectionController /** A data source that transforms a top-level object into view models, and returns cells and sizes for given view models. @@ -59,6 +59,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, weak, nullable) id selectionDelegate; +/** + The object currently assigned to the section controller, if any. + */ +@property (nonatomic, strong, readonly, nullable) ObjectType object; + /** The array of view models created from the data source. Values are changed when the top-level object changes or by calling `-updateAnimated:completion:` manually. diff --git a/Source/IGListBindingSectionController.m b/Source/IGListBindingSectionController.m index 5dffe5a2..ce1617fd 100644 --- a/Source/IGListBindingSectionController.m +++ b/Source/IGListBindingSectionController.m @@ -54,7 +54,11 @@ typedef NS_ENUM(NSInteger, IGListDiffingSectionState) { } oldViewModels = self.viewModels; - self.viewModels = [self.dataSource sectionController:self viewModelsForObject:self.object]; + + id object = self.object; + IGAssert(object != nil, @"Expected IGListBindingSectionController object to be non-nil before updating."); + + self.viewModels = [self.dataSource sectionController:self viewModelsForObject:object]; result = IGListDiff(oldViewModels, self.viewModels, IGListDiffEquality); [result.updates enumerateIndexesUsingBlock:^(NSUInteger oldUpdatedIndex, BOOL *stop) {