IGListUpdatingDelegate

Objective-C

@protocol IGListUpdatingDelegate <NSObject>

Swift

protocol ListUpdatingDelegate : NSObjectProtocol

Implement this protocol in order to handle both section and row based update events. Implementation should forward or coalesce these events to a backing store or collection.

  • Asks the delegate for the pointer functions for looking up an object in a collection.

    Note

    Since the updating delegate is responsible for transitioning between object sets, it becomes the “source of truth” for how objects and their corresponding section controllers are mapped. This allows the updater to control if objects are looked up by pointer, or more traditionally, with -hash/-isEqual.

    For behavior similar to NSDictionary, simply return +[NSPointerFunctions pointerFunctionsWithOptions:NSPointerFunctionsObjectPersonality].

    Declaration

    Objective-C

    - (nonnull NSPointerFunctions *)objectLookupPointerFunctions;

    Swift

    func objectLookupPointerFunctions() -> NSPointerFunctions

    Return Value

    Pointer functions for looking up an object in a collection.

  • Perform a section update from an old array of objects to a new one.

    Note

    Implementations determine how to transition between objects. You can perform a diff on the objects, reload each section, or simply call -reloadData on the collection view. In the end, the collection view must be setup with a section for each object in the toObjects array.

    The applySectionDataBlock block should be called prior to making any UICollectionView updates, passing in the toObjects that the updater is applying.

    Declaration

    Objective-C

    - (void)performUpdateWithCollectionViewBlock:
                (nonnull IGListCollectionViewBlock)collectionViewBlock
                                        animated:(BOOL)animated
                                sectionDataBlock:(nonnull IGListTransitionDataBlock)
                                                     sectionDataBlock
                           applySectionDataBlock:
                               (nonnull IGListTransitionDataApplyBlock)
                                   applySectionDataBlock
                                      completion:(nullable IGListUpdatingCompletion)
                                                     completion;

    Swift

    func performUpdate(collectionViewBlock: @escaping ListCollectionViewBlock, animated: Bool, sectionDataBlock: @escaping ListTransitionDataBlock, applySectionDataBlock: @escaping ListTransitionDataApplyBlock) async -> Bool

    Parameters

    collectionViewBlock

    A block returning the collecion view to perform updates on.

    animated

    A flag indicating if the transition should be animated.

    sectionDataBlock

    A block that returns the section information (ex: from and to objects)

    applySectionDataBlock

    A block that must be called when the adapter applies changes to the collection view.

    completion

    A completion block to execute when the update is finished.

  • Perform an item update block in the collection view.

    Declaration

    Objective-C

    - (void)performUpdateWithCollectionViewBlock:
                (nonnull IGListCollectionViewBlock)collectionViewBlock
                                        animated:(BOOL)animated
                                     itemUpdates:
                                         (nonnull IGListItemUpdateBlock)itemUpdates
                                      completion:(nullable IGListUpdatingCompletion)
                                                     completion;

    Swift

    func performUpdate(collectionViewBlock: @escaping ListCollectionViewBlock, animated: Bool, itemUpdates: @escaping ListItemUpdateBlock) async -> Bool

    Parameters

    collectionViewBlock

    A block returning the collecion view to perform updates on.

    animated

    A flag indicating if the transition should be animated.

    itemUpdates

    A block containing all of the updates.

    completion

    A completion block to execute when the update is finished.

  • Perform a [UICollectionView setDataSource:...] swap within this block. It gives the updater the chance to cancel or execute any on-going updates. The block should be executed synchronously.

    Declaration

    Objective-C

    - (void)performDataSourceChange:(nonnull IGListDataSourceChangeBlock)block;

    Swift

    func performDataSourceChange(_ block: @escaping ListDataSourceChangeBlock)

    Parameters

    block

    The block that will actuallty change the dataSource

  • Completely reload data in the collection.

    Declaration

    Objective-C

    - (void)reloadDataWithCollectionViewBlock:
                (nonnull IGListCollectionViewBlock)collectionViewBlock
                            reloadUpdateBlock:
                                (nonnull IGListReloadUpdateBlock)reloadUpdateBlock
                                   completion:(nullable IGListUpdatingCompletion)
                                                  completion;

    Swift

    func reloadData(collectionViewBlock: @escaping ListCollectionViewBlock, reloadUpdate reloadUpdateBlock: @escaping ListReloadUpdateBlock) async -> Bool

    Parameters

    collectionViewBlock

    A block returning the collecion view to reload.

    reloadUpdateBlock

    A block that must be called when the adapter reloads the collection view.

    completion

    A completion block to execute when the reload is finished.

  • Tells the delegate to perform item inserts at the given index paths.

    Declaration

    Objective-C

    - (void)insertItemsIntoCollectionView:(nonnull UICollectionView *)collectionView
                               indexPaths:
                                   (nonnull NSArray<NSIndexPath *> *)indexPaths;

    Swift

    func insertItems(into collectionView: UICollectionView, indexPaths: [IndexPath])

    Parameters

    collectionView

    The collection view on which to perform the transition.

    indexPaths

    The index paths to insert items into.

  • Tells the delegate to perform item deletes at the given index paths.

    Declaration

    Objective-C

    - (void)deleteItemsFromCollectionView:(nonnull UICollectionView *)collectionView
                               indexPaths:
                                   (nonnull NSArray<NSIndexPath *> *)indexPaths;

    Swift

    func deleteItems(from collectionView: UICollectionView, indexPaths: [IndexPath])

    Parameters

    collectionView

    The collection view on which to perform the transition.

    indexPaths

    The index paths to delete items from.

  • Tells the delegate to move an item from and to given index paths.

    Declaration

    Objective-C

    - (void)moveItemInCollectionView:(nonnull UICollectionView *)collectionView
                       fromIndexPath:(nonnull NSIndexPath *)fromIndexPath
                         toIndexPath:(nonnull NSIndexPath *)toIndexPath;

    Swift

    func moveItem(in collectionView: UICollectionView, from fromIndexPath: IndexPath, to toIndexPath: IndexPath)

    Parameters

    collectionView

    The collection view on which to perform the transition.

    fromIndexPath

    The source index path of the item to move.

    toIndexPath

    The destination index path of the item to move.

  • Tells the delegate to reload an item from and to given index paths.

    Note

    Since UICollectionView is unable to handle calling -[UICollectionView reloadItemsAtIndexPaths:] safely while also executing insert and delete operations in the same batch updates, the updater must know about the origin and destination of the reload to perform a safe transition.

    Declaration

    Objective-C

    - (void)reloadItemInCollectionView:(nonnull UICollectionView *)collectionView
                         fromIndexPath:(nonnull NSIndexPath *)fromIndexPath
                           toIndexPath:(nonnull NSIndexPath *)toIndexPath;

    Swift

    func reloadItem(in collectionView: UICollectionView, from fromIndexPath: IndexPath, to toIndexPath: IndexPath)

    Parameters

    collectionView

    The collection view on which to perform the transition.

    fromIndexPath

    The source index path of the item to reload.

    toIndexPath

    The destination index path of the item to reload.

  • Tells the delegate to move a section from and to given indexes.

    Declaration

    Objective-C

    - (void)moveSectionInCollectionView:(nonnull UICollectionView *)collectionView
                              fromIndex:(NSInteger)fromIndex
                                toIndex:(NSInteger)toIndex;

    Swift

    func moveSection(in collectionView: UICollectionView, from fromIndex: Int, to toIndex: Int)

    Parameters

    collectionView

    The collection view on which to perform the transition.

    fromIndex

    The source index of the section to move.

    toIndex

    The destination index of the section to move.

  • Completely reload each section in the collection view.

    Declaration

    Objective-C

    - (void)reloadCollectionView:(nonnull UICollectionView *)collectionView
                        sections:(nonnull NSIndexSet *)sections;

    Swift

    func reload(_ collectionView: UICollectionView, sections: IndexSet)

    Parameters

    collectionView

    The collection view to reload.

    sections

    The sections to reload.