IGListAdapter
@interface IGListAdapter : NSObject
IGListAdapter objects provide an abstraction for feeds of objects in a UICollectionView by breaking each object into
individual sections, called section controllers
. These controllers (objects conforming to IGListSectionType) act as a
data source and delegate for each section.
Feed implementations must act as the data source for an IGListAdapter in order to drive the objects and section
controllers in a collection view.
-
The view controller that houses the adapter.
Declaration
Objective-C
@property (readwrite, nonatomic, nullable) UIViewController *viewController; -
The collection view used with the adapter.
Declaration
Objective-C
@property (readwrite, nonatomic, nullable) IGListCollectionView *collectionView; -
The object that acts as the data source for the list adapter.
Declaration
Objective-C
@property (readwrite, nonatomic, nullable) id<IGListAdapterDataSource> dataSource;Swift
weak var dataSource: AnyObject? { get set } -
The object that receives top-level events for section controllers.
Declaration
Objective-C
@property (readwrite, nonatomic, nullable) id<IGListAdapterDelegate> delegate;Swift
weak var delegate: AnyObject? { get set } -
The object that receives
UICollectionViewDelegateevents.Note
This object will not receiveUIScrollViewDelegateevents. Instead use scrollViewDelegate.Declaration
Objective-C
@property (readwrite, nonatomic, nullable) id<UICollectionViewDelegate> collectionViewDelegate;Swift
weak var collectionViewDelegate: AnyObject? { get set } -
The object that receives
UIScrollViewDelegateevents.Declaration
Objective-C
@property (readwrite, nonatomic, nullable) id<UIScrollViewDelegate> scrollViewDelegate;Swift
weak var scrollViewDelegate: AnyObject? { get set } -
The updater for this list adapter.
Declaration
Objective-C
@property (readonly, strong, nonatomic) id<IGListUpdatingDelegate> _Nonnull updater; -
A bitmask of experiments to conduct on the adapter.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) IGListExperiment experiments;Swift
var experiments: Int32 { get set } -
Initializes a new
IGListAdapterobject.Note
The working range is the number of objects beyond the visible objects (plus and minus) that should be notified when they are close to being visible. For instance, if you have 3 objects on screen and a working range of 2, the previous and succeeding 2 objects will be notified that they are within the working range. As you scroll the list the range is updated as objects enter and exit the working range.
To opt out of using the working range, you can provide a value of
0.Declaration
Objective-C
- (nonnull instancetype) initWithUpdater:(nonnull id<IGListUpdatingDelegate>)updater viewController:(nullable UIViewController *)viewController workingRangeSize:(NSInteger)workingRangeSize;Parameters
updaterAn object that manages updates to the collection view.
viewControllerThe view controller that will house the adapter.
workingRangeSizeThe number of objects before and after the viewport to consider within the working range.
Return Value
A new list adapter object.
-
Perform an update from the previous state of the data source. This is analagous to calling
-[UICollectionView performBatchUpdates:completion:].Declaration
Objective-C
- (void)performUpdatesAnimated:(BOOL)animated completion:(nullable IGListUpdaterCompletion)completion;Swift
func performUpdatesAnimated(_ animated: Any!, completion: Any!)Parameters
animatedA flag indicating if the transition should be animated.
completionThe block to execute when the update completes.
-
Perform an immediate reload of the data in the data source, discarding the old objects.
Declaration
Objective-C
- (void)reloadDataWithCompletion:(nullable IGListUpdaterCompletion)completion;Swift
func reloadData(withCompletion completion: Any!)Parameters
completionThe block to execute when the reload completes.
-
Reload the list for only the specified objects.
Declaration
Objective-C
- (void)reloadObjects:(nonnull NSArray *)objects;Swift
func reloadObjects(_ objects: Any!)Parameters
objectsThe objects to reload.
-
Query the section index of a list. Constant time lookup.
Declaration
Objective-C
- (NSInteger)sectionForSectionController: (nonnull IGListSectionController<IGListSectionType> *)sectionController;Swift
func section(for sectionController: IGListSectionController!) -> Any!Parameters
sectionControllerA list object.
Return Value
The section index of the list if it exists, otherwise
NSNotFound. -
Returns the section controller for the specified object. Constant time lookup.
See
-[IGListAdapterDataSource listAdapter:sectionControllerForObject:]Declaration
Objective-C
- (__kindof IGListSectionController<IGListSectionType> *_Nullable) sectionControllerForObject:(nonnull id)object;Swift
func sectionController(for object: Any!) -> IGListSectionController?Parameters
objectAn object from the data source.
Return Value
An section controller or
nilifobjectis not in the list. -
Returns the object corresponding to the specified section controller in the list. Constant time lookup.
Declaration
Objective-C
- (nullable id)objectForSectionController: (nonnull IGListSectionController<IGListSectionType> *)sectionController;Swift
func object(for sectionController: IGListSectionController!) -> Any?Parameters
sectionControllerA section controller in the list.
Return Value
The object for the specified section controller, or nil if not found.
-
Returns the object corresponding to a section in the list. Constant time lookup.
Declaration
Objective-C
- (nullable id)objectAtSection:(NSInteger)section;Swift
func object(atSection section: Any!) -> Any?Parameters
sectionA section in the list.
Return Value
The object for the specified section, or
nilif the section does not exist. -
Returns the section corresponding to the specified object in the list. Constant time lookup.
Declaration
Objective-C
- (NSInteger)sectionForObject:(nonnull id)object;Swift
func section(for object: Any!) -> Any!Parameters
objectAn object in the list.
Return Value
The section index of
objectif found, otherwiseNSNotFound. -
Returns a copy of all the objects currently powering the adapter.
Declaration
Objective-C
- (nonnull NSArray *)objects;Swift
func objects() -> Any!Return Value
An array of objects.
-
An unordered array of the currently visible section controllers.
Declaration
Objective-C
- (nonnull NSArray<IGListSectionController<IGListSectionType> *> *) visibleSectionControllers;Swift
func visibleSectionControllers() -> Any!Return Value
An array of section controllers.
-
An unordered array of the currently visible objects.
Declaration
Objective-C
- (nonnull NSArray *)visibleObjects;Swift
func visibleObjects() -> Any!Return Value
An array of objects
-
Scrolls to the sepcified object in the list adapter.
Declaration
Objective-C
- (void)scrollToObject:(nonnull id)object supplementaryKinds:(nullable NSArray<NSString *> *)supplementaryKinds scrollDirection:(UICollectionViewScrollDirection)scrollDirection scrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated;Swift
func scroll(to object: Any!, supplementaryKinds: Any!, scrollDirection: Any!, scrollPosition: Any!, animated: Any!)Parameters
objectThe object to which to scroll.
supplementaryKindsThe types of supplementary views in the section.
scrollDirectionAn option indicating the direction to scroll.
scrollPositionAn option that specifies where the item should be positioned when scrolling finishes.
animatedA flag indicating if the scrolling should be animated.
-
Returns the size of a cell at the specified index path.
Declaration
Objective-C
- (CGSize)sizeForItemAtIndexPath:(nonnull NSIndexPath *)indexPath;Swift
func sizeForItem(atIndexPath indexPath: Any!) -> Any!Parameters
indexPathThe index path of the cell.
Return Value
The size of the cell.
-
Returns the size of a supplementary view in the list at the specified index path.
Declaration
Objective-C
- (CGSize)sizeForSupplementaryViewOfKind:(nonnull NSString *)elementKind atIndexPath:(nonnull NSIndexPath *)indexPath;Swift
func sizeForSupplementaryView(ofKind elementKind: Any!, atIndexPath indexPath: Any!) -> Any!Parameters
elementKindThe kind of supplementary view.
indexPathThe index path of the supplementary view.
Return Value
The size of the supplementary view.
View on GitHub
IGListAdapter Class Reference