# IGListBindingSectionController Class Reference

# IGListBindingSectionController

    @interface IGListBindingSectionController<
        __covariant ObjectType : id <IGListDiffable>> : IGListSectionController

This section controller uses a data source to transform its top level object into an array of diffable view models. It then automatically binds each view model to cells via the `IGListBindable` protocol.

Models used with `IGListBindingSectionController` should take special care to always return `YES` for identical objects. That is, any objects with matching `-diffIdentifier`s should always be equal, that way the section controller can create new view models via the data source, create a diff, and update the specific cells that have changed.

In Objective-C, your `-isEqualToDiffableObject:` can simply be:

    - (BOOL)isEqualToDiffableObject:(id)object {
      return YES;
    }

In Swift:

    func isEqual(toDiffableObject object: IGListDiffable?) -> Bool {
      return true
    }

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.

- `dataSource`

  A data source that transforms a top-level object into view models, and returns cells and sizes for given view models.

  #### Declaration

  Objective-C

      @property (readwrite, nonatomic, nullable)
          id<IGListBindingSectionControllerDataSource>
              dataSource;

  Swift

      weak var dataSource: ListBindingSectionControllerDataSource? { get set }

- `selectionDelegate`

  A delegate that receives selection events from cells in an `IGListBindingSectionController` instance.

  #### Declaration

  Objective-C

      @property (readwrite, nonatomic, nullable)
          id<IGListBindingSectionControllerSelectionDelegate>
              selectionDelegate;

  Swift

      weak var selectionDelegate: ListBindingSectionControllerSelectionDelegate? { get set }

- `object`

  The object currently assigned to the section controller, if any.

  #### Declaration

  Objective-C

      @property (readonly, strong, nonatomic, nullable) ObjectType object;

  Swift

      var object: ObjectType? { get }

- `viewModels`

  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.

  #### Declaration

  Objective-C

      @property (readonly, strong, nonatomic)
          NSArray<id<IGListDiffable>> *_Nonnull viewModels;

  Swift

      var viewModels: [ListDiffable] { get }

- `-updateAnimated:completion:`

  Tells the section controller to query for new view models, diff the changes, and update its cells.

  #### Declaration

  Objective-C

      - (void)updateAnimated:(BOOL)animated
                  completion:(nullable void (^)(BOOL))completion;

  Swift

      func update(animated: Bool, completion: ((Bool) -> Void)? = nil)

  #### Parameters

  `animated` | A flag indicating if the transition should be animated or not.
  `completion` | An optional completion block executed after updates finish. Parameter is YES if updates were applied.

- `-moveObjectFromIndex:toIndex:`

  Notifies the section that a list object should move within a section as the result of interactive reordering.

  Note

  this method must be implemented if interactive reordering is enabled. To ensure updating the internal viewModels array, calling super is required, preferably before your own implementation.

  #### Declaration

  Objective-C

      - (void)moveObjectFromIndex:(NSInteger)sourceIndex
                          toIndex:(NSInteger)destinationIndex;

  Swift

      func moveObject(from sourceIndex: Int, to destinationIndex: Int)

  #### Parameters

  `sourceIndex` | The starting index of the object.
  `destinationIndex` | The ending index of the object.

© 2019 Instagram. All rights reserved. (Last updated: 2019-11-20)

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