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 subclassing to
IGListSectionController) 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;Swift
weak var viewController: UIViewController? { get set } -
The collection view used with the adapter.
Note
Setting this property will automatically set isPrefetchingEnabled toNOfor performance reasons.Declaration
Objective-C
@property (readwrite, nonatomic, nullable) UICollectionView *collectionView;Swift
weak var collectionView: UICollectionView? { get set } -
The object that acts as the data source for the adapter.
Declaration
Objective-C
@property (readwrite, nonatomic, nullable) id<IGListAdapterDataSource> dataSource;Swift
weak var dataSource: ListAdapterDataSource? { 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: IGListAdapterDelegate? { 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: UICollectionViewDelegate? { get set } -
The object that receives
UIScrollViewDelegateevents.Declaration
Objective-C
@property (readwrite, nonatomic, nullable) id<UIScrollViewDelegate> scrollViewDelegate;Swift
weak var scrollViewDelegate: UIScrollViewDelegate? { get set } -
The updater for the 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: IGListExperiment { 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, use
initWithUpdater:viewController:or provide a working range of0.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.
-
Initializes a new
IGListAdapterobject with a working range of0.Declaration
Objective-C
- (nonnull instancetype) initWithUpdater:(nonnull id<IGListUpdatingDelegate>)updater viewController:(nullable UIViewController *)viewController;Parameters
updaterAn object that manages updates to the collection view.
viewControllerThe view controller that will house the adapter.
Return Value
A new list adapter object.
-
Perform an update from the previous state of the data source. This is analogous to calling
-[UICollectionView performBatchUpdates:completion:].Declaration
Objective-C
- (void)performUpdatesAnimated:(BOOL)animated completion:(nullable IGListUpdaterCompletion)completion;Swift
func performUpdates(animated: Bool, completion: ListUpdaterCompletion? = nil)Parameters
animatedA flag indicating if the transition should be animated.
completionThe block to execute when the updates complete.
-
Perform an immediate reload of the data in the data source, discarding the old objects.
Warning
Do not use this method to update without animations as it can be very expensive to teardown and rebuild all section controllers. Use
-[IGListAdapter performUpdatesAnimated:completion]instead.Declaration
Objective-C
- (void)reloadDataWithCompletion:(nullable IGListUpdaterCompletion)completion;Swift
func reloadData(completion: ListUpdaterCompletion? = nil)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 controller at a given section index. Constant time lookup.
Declaration
Objective-C
- (nullable IGListSectionController *)sectionControllerForSection: (NSInteger)section;Swift
func sectionController(forSection section: Int) -> IGListSectionController?Parameters
sectionA section in the list.
Return Value
A section controller or
nilif the section does not exist. -
Query the section index of a list. Constant time lookup.
Declaration
Objective-C
- (NSInteger)sectionForSectionController: (nonnull IGListSectionController *)sectionController;Swift
func section(for sectionController: IGListSectionController) -> IntParameters
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.
Declaration
Objective-C
- (__kindof IGListSectionController *_Nullable)sectionControllerForObject: (nonnull id)object;Swift
func sectionController(for object: Any) -> IGListSectionController?Parameters
objectAn object from the data source.
Return Value
A 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 *)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
nilif 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: Int) -> 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) -> IntParameters
objectAn object in the list.
Return Value
The section index of
objectif found, otherwiseNSNotFound. -
Returns a copy of all the objects currently driving 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 *> *)visibleSectionControllers;Swift
func visibleSectionControllers() -> [IGListSectionController]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
-
An unordered array of the currently visible cells for a given object.
Declaration
Objective-C
- (nonnull NSArray<UICollectionViewCell *> *)visibleCellsForObject: (nonnull id)object;Swift
func visibleCells(for object: Any) -> [UICollectionViewCell]Parameters
objectAn object in the list
Return Value
An array of collection view cells.
-
Scrolls to the specified 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: [String]?, scrollDirection: UICollectionViewScrollDirection, scrollPosition: UICollectionViewScrollPosition, animated: Bool)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(at indexPath: IndexPath) -> CGSizeParameters
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: String, at indexPath: IndexPath) -> CGSizeParameters
elementKindThe kind of supplementary view.
indexPathThe index path of the supplementary view.
Return Value
The size of the supplementary view.
-
Adds a listener to the list adapter.
Note
Listeners are held weakly so there is no need to call
-[IGListAdapter removeUpdateListener:]ondealloc.Declaration
Objective-C
- (void)addUpdateListener: (nonnull id<IGListAdapterUpdateListener>)updateListener;Swift
func add(_ updateListener: ListAdapterUpdateListener)Parameters
updateListenerThe object conforming to the
IGListAdapterUpdateListenerprotocol. -
Removes a listener from the list adapter.
Declaration
Objective-C
- (void)removeUpdateListener: (nonnull id<IGListAdapterUpdateListener>)updateListener;Swift
func remove(_ updateListener: ListAdapterUpdateListener)Parameters
updateListenerThe object conforming to the
IGListAdapterUpdateListenerprotocol.