# IGListCollectionContext

    @protocol IGListCollectionContext <NSObject>

The collection context provides limited access to the collection-related information that section controllers need for operations like sizing, dequeing cells, insterting, deleting, reloading, etc.

- `containerSize`

  The size of the collection view. You may use this for sizing cells.

  #### Declaration

  Objective-C

      @property (readonly, nonatomic) CGSize containerSize;

  Swift

      var containerSize: Int32 { get }

- `-indexForCell:sectionController:`

  Returns the index of the specified cell in the collection relative to the section controller.

  #### Declaration

  Objective-C

      - (NSInteger)indexForCell:(nonnull UICollectionViewCell *)cell
              sectionController:(nonnull IGListSectionController<IGListSectionType> *)
                                    sectionController;

  Swift

      func index(forCell cell: Any!, sectionController: Any!) -> Any!

  #### Parameters

  `cell` | An existing cell in the collection.
  `sectionController` | The section controller requesting this information.

  #### Return Value

  The index of the cell or `NSNotFound` if it does not exist in the collection.

- `-cellForItemAtIndex:sectionController:`

  Returns the cell in the collection at the specified index for the section controller.

  Warning

  This method may return `nil` if the cell is offscreen.

  #### Declaration

  Objective-C

      - (nullable __kindof UICollectionViewCell *)
      cellForItemAtIndex:(NSInteger)index
       sectionController:
           (nonnull IGListSectionController<IGListSectionType> *)sectionController;

  Swift

      func cellForItem(atIndex index: Any!, sectionController: Any!) -> Any!

  #### Parameters

  `index` | The index of the desired cell.
  `sectionController` | The section controller requesting this information.

  #### Return Value

  The collection view cell, or `nil` if not found.

- `-visibleCellsForSectionController:`

  Returns the visible cells for the given section controller.

  #### Declaration

  Objective-C

      - (nonnull NSArray<UICollectionViewCell *> *)visibleCellsForSectionController:
          (nonnull IGListSectionController<IGListSectionType> *)sectionController;

  Swift

      func visibleCells(forSectionController sectionController: Any!) -> Any!

  #### Parameters

  `sectionController` | The section controller requesting this information.

  #### Return Value

  An array of visible cells, or an empty array if none are found.

- `-deselectItemAtIndex:sectionController:animated:`

  Deselects a cell in the collection.

  #### Declaration

  Objective-C

      - (void)deselectItemAtIndex:(NSInteger)index
                sectionController:
                    (nonnull IGListSectionController<IGListSectionType> *)
                        sectionController
                         animated:(BOOL)animated;

  Swift

      func deselectItem(atIndex index: Any!, sectionController: Any!, animated: Any!)

  #### Parameters

  `index` | The index of the item to deselect.
  `sectionController` | The section controller requesting this information.
  `animated` | Pass `YES` to animate the change, `NO` otherwise.

- `-sectionForSectionController:`

  Returns the section index of an section controller.

  #### Declaration

  Objective-C

      - (NSInteger)sectionForSectionController:
          (nonnull IGListSectionController<IGListSectionType> *)sectionController;

  Swift

      func section(forSectionController sectionController: Any!) -> Any!

  #### Parameters

  `sectionController` | An section controller object.

  #### Return Value

  The section index of the controller if found, otherwise `NSNotFound`.

- `-dequeueReusableCellOfClass:forSectionController:atIndex:`

  Dequeues a cell from the collection view reuse pool.

  Note

  This method uses a string representation of the cell class as the identifier.

  #### Declaration

  Objective-C

      - (nonnull __kindof UICollectionViewCell *)
      dequeueReusableCellOfClass:(nonnull Class)cellClass
            forSectionController:
                (nonnull IGListSectionController<IGListSectionType> *)
                    sectionController
                         atIndex:(NSInteger)index;

  Swift

      func dequeueReusableCell(of cellClass: AnyClass!, forSectionController sectionController: Any!, atIndex index: Any!) -> Any!

  #### Parameters

  `cellClass` | The class of the cell you want to dequeue.
  `sectionController` | The section controller requesting this information.
  `index` | The index of the cell.

  #### Return Value

  A cell dequeued from the reuse pool or a newly created one.

- `-dequeueReusableCellWithNibName:bundle:forSectionController:atIndex:`

  Dequeues a cell from the collection view reuse pool.

  Note

  This method uses a string representation of the cell class as the identifier.

  #### Declaration

  Objective-C

      - (nonnull __kindof UICollectionViewCell *)
      dequeueReusableCellWithNibName:(nonnull NSString *)nibName
                              bundle:(nullable NSBundle *)bundle
                forSectionController:
                    (nonnull IGListSectionController<IGListSectionType> *)
                        sectionController
                             atIndex:(NSInteger)index;

  Swift

      func dequeueReusableCell(withNibName nibName: Any!, bundle: Any!, forSectionController sectionController: Any!, atIndex index: Any!) -> Any!

  #### Parameters

  `nibName` | The name of the nib file.
  `bundle` | The bundle in which to search for the nib file. If `nil`, this method searches the main bundle.
  `sectionController` | The section controller requesting this information.
  `index` | The index of the cell.

  #### Return Value

  A cell dequeued from the reuse pool or a newly created one.

- `-dequeueReusableCellFromStoryboardWithIdentifier:forSectionController:atIndex:`

  Dequeues a storyboard prototype cell from the collection view reuse pool.

  #### Declaration

  Objective-C

      - (nonnull __kindof UICollectionViewCell *)
      dequeueReusableCellFromStoryboardWithIdentifier:(nonnull NSString *)identifier
                                 forSectionController:
                                     (nonnull IGListSectionController<
                                         IGListSectionType> *)sectionController
                                              atIndex:(NSInteger)index;

  Swift

      func dequeueReusableCellFromStoryboard(withIdentifier identifier: Any!, forSectionController sectionController: Any!, atIndex index: Any!) -> Any!

  #### Parameters

  `identifier` | The identifier of the cell prototype in storyboard.
  `sectionController` | The section controller requesting this information.
  `index` | The index of the cell.

  #### Return Value

  A cell dequeued from the reuse pool or a newly created one.

- `-dequeueReusableSupplementaryViewOfKind:forSectionController:class:atIndex:`

  Dequeues a supplementary view from the collection view reuse pool.

  Note

  This method uses a string representation of the view class as the identifier.

  #### Declaration

  Objective-C

      - (nonnull __kindof UICollectionReusableView *)
      dequeueReusableSupplementaryViewOfKind:(nonnull NSString *)elementKind
                        forSectionController:
                            (nonnull IGListSectionController<IGListSectionType> *)
                                sectionController
                                       class:(nonnull Class)viewClass
                                     atIndex:(NSInteger)index;

  Swift

      func dequeueReusableSupplementaryView(ofKind elementKind: Any!, forSectionController sectionController: Any!, class viewClass: AnyClass!, atIndex index: Any!) -> Any!

  #### Parameters

  `elementKind` | The kind of supplementary veiw.
  `sectionController` | The section controller requesting this information.
  `viewClass` | The class of the supplementary view.
  `index` | The index of the supplementary vew.

  #### Return Value

  A supplementary view dequeued from the reuse pool or a newly created one.

- `-dequeueReusableSupplementaryViewFromStoryboardOfKind:withIdentifier:forSectionController:atIndex:`

  Dequeues a supplementary view from the collection view reuse pool.

  #### Declaration

  Objective-C

      - (nonnull __kindof UICollectionReusableView *)
      dequeueReusableSupplementaryViewFromStoryboardOfKind:
          (nonnull NSString *)elementKind
                                            withIdentifier:
                                                (nonnull NSString *)identifier
                                      forSectionController:
                                          (nonnull IGListSectionController<
                                              IGListSectionType> *)sectionController
                                                   atIndex:(NSInteger)index;

  Swift

      func dequeueReusableSupplementaryView(fromStoryboardOfKind elementKind: Any!, withIdentifier identifier: Any!, forSectionController sectionController: Any!, atIndex index: Any!) -> Any!

  #### Parameters

  `elementKind` | The kind of supplementary veiw.
  `identifier` | The identifier of the supplementary view in storyboard.
  `sectionController` | The section controller requesting this information.
  `index` | The index of the supplementary vew.

  #### Return Value

  A supplementary view dequeued from the reuse pool or a newly created one.

- `-dequeueReusableSupplementaryViewOfKind:forSectionController:nibName:bundle:atIndex:`

  Dequeues a supplementary view from the collection view reuse pool.

  Note

  This method uses a string representation of the view class as the identifier.

  #### Declaration

  Objective-C

      - (nonnull __kindof UICollectionReusableView *)
      dequeueReusableSupplementaryViewOfKind:(nonnull NSString *)elementKind
                        forSectionController:
                            (nonnull IGListSectionController<IGListSectionType> *)
                                sectionController
                                     nibName:(nonnull NSString *)nibName
                                      bundle:(nullable NSBundle *)bundle
                                     atIndex:(NSInteger)index;

  Swift

      func dequeueReusableSupplementaryView(ofKind elementKind: Any!, forSectionController sectionController: Any!, nibName: Any!, bundle: Any!, atIndex index: Any!) -> Any!

  #### Parameters

  `elementKind` | The kind of supplementary veiw.
  `sectionController` | The section controller requesting this information.
  `nibName` | The name of the nib file.
  `bundle` | The bundle in which to search for the nib file. If `nil`, this method searches the main bundle.
  `index` | The index of the supplementary vew.

  #### Return Value

  A supplementary view dequeued from the reuse pool or a newly created one.

- `-reloadInSectionController:atIndexes:`

  Reloads cells in the section controller.

  #### Declaration

  Objective-C

      - (void)reloadInSectionController:
                  (nonnull IGListSectionController<IGListSectionType> *)
                      sectionController
                              atIndexes:(nonnull NSIndexSet *)indexes;

  Swift

      func reload(inSectionController sectionController: Any!, atIndexes indexes: Any!)

  #### Parameters

  `sectionController` | The section controller who’s cells need reloading.
  `indexes` | The indexes of items that need reloading.

- `-insertInSectionController:atIndexes:`

  Inserts cells in the list.

  #### Declaration

  Objective-C

      - (void)insertInSectionController:
                  (nonnull IGListSectionController<IGListSectionType> *)
                      sectionController
                              atIndexes:(nonnull NSIndexSet *)indexes;

  Swift

      func insert(inSectionController sectionController: Any!, atIndexes indexes: Any!)

  #### Parameters

  `sectionController` | The section controller who’s cells need inserting.
  `indexes` | The indexes of items that need inserting.

- `-deleteInSectionController:atIndexes:`

  Deletes cells in the list.

  #### Declaration

  Objective-C

      - (void)deleteInSectionController:
                  (nonnull IGListSectionController<IGListSectionType> *)
                      sectionController
                              atIndexes:(nonnull NSIndexSet *)indexes;

  Swift

      func delete(inSectionController sectionController: Any!, atIndexes indexes: Any!)

  #### Parameters

  `sectionController` | The section controller who’s cells need deleted.
  `indexes` | The indexes of items that need deleting.

- `-reloadSectionController:`

  Reloads the entire section controller.

  #### Declaration

  Objective-C

      - (void)reloadSectionController:
          (nonnull IGListSectionController<IGListSectionType> *)sectionController;

  Swift

      func reloadSectionController(_ sectionController: Any!)

  #### Parameters

  `sectionController` | The section controller who’s cells need reloading.

- `-performBatchAnimated:updates:completion:`

  Batches and performs many cell-level updates in a single transaction.

  Note

  Use this method to batch cell updates (inserts, deletes, reloads) into a single transaction. This lets you make many changes to your data store and perform all the transitions at once.

  For example, inside your section controllers, you may want to delete and insert into the data source that backs your section controller. For example:

      [self.collectionContext performBatchItemUpdates:^{
      // perform data source changes inside the update block
      [self.items addObject:newItem];
      [self.items removeObjectAtIndex:0];

      NSIndexSet *inserts = [NSIndexSet indexSetWithIndex:[self.items count] - 1];
      [self.collectionContext insertInSectionController:self atIndexes:inserts];

      NSIndexSet *deletes = [NSIndexSet indexSetWithIndex:0];
      [self.collectionContext deleteInSectionController:self atIndexes:deletes];
      } completion:nil];

  Warning

  You must perform data modifications inside the update block. Updates will not be performed synchronously, so you should make sure that your data source changes only when necessary.

  #### Declaration

  Objective-C

      - (void)performBatchAnimated:(BOOL)animated
                           updates:(nonnull void (^)())updates
                        completion:(nullable void (^)(BOOL))completion;

  Swift

      func performBatchAnimated(_ animated: Any!, updates: (() -> Void)!, completion: ((Int32) -> Void)? = nil)

  #### Parameters

  `animated` | A flag indicating if the transition should be animated.
  `updates` | A block containing all of the cell updates.
  `completion` | An optional completion block to execute when the updates are finished.

- `-scrollToSectionController:atIndex:scrollPosition:animated:`

  Scrolls to the specified section controller in the list.

  #### Declaration

  Objective-C

      - (void)scrollToSectionController:
                  (nonnull IGListSectionController<IGListSectionType> *)
                      sectionController
                                atIndex:(NSInteger)index
                         scrollPosition:(UICollectionViewScrollPosition)scrollPosition
                               animated:(BOOL)animated;

  Swift

      func scroll(toSectionController sectionController: Any!, atIndex index: Any!, scrollPosition: Any!, animated: Any!)

  #### Parameters

  `sectionController` | The section controller.
  `index` | The index of the item in the section controller to which to scroll.
  `scrollPosition` | An option that specifies where the item should be positioned when scrolling finishes.
  `animated` | A flag indicating if the scrolling should be animated.

© 2017 Instagram. All rights reserved. (Last updated: 2017-01-04)

Generated by jazzy ♪♫ v0.7.3, a Realm project.