IGListKit Tutorial: Better UICollectionViews

In this IGListKit tutorial, you’ll learn to build better, more dynamic UICollectionViews with Instagram’s data-driven framework. By Ron Kliffer.

4.8 (28) · 2 Reviews

Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Performing Updates

JPL is ecstatic about your progress!

While you were working, the director of NASA coordinated a rescue operation for the astronaut, requiring him to launch and intercept with another ship! It’s going to be a complicated launch, so he’ll have to liftoff at precisely the right time.

JPL engineering extended the messaging module with real-time chat and they are asking you to integrate it.

Open FeedViewController.swift and add the following lines to the end of viewDidLoad():

pathfinder.delegate = self
pathfinder.connect()

The Pathfinder module is all patched up with real-time support. All you need to do is connect to the unit and respond to delegate events.

Add the following extension to the bottom of the file:

// MARK: - PathfinderDelegate
extension FeedViewController: PathfinderDelegate {
  func pathfinderDidUpdateMessages(pathfinder: Pathfinder) {
    adapter.performUpdates(animated: true)
  }
}

FeedViewController now conforms to PathfinderDelegate. The single method performUpdates(animated:) tells the ListAdapter to ask its data source for new objects and then update the UI. This handles objects that are deleted, updated, moved or inserted.

Build and run to see the captain’s messages updating! All you had to do was add one single method for IGListKit to determine what has changed in the data source and animate the changes when new data arrives:

IGListKit

All you need to do now is transmit the latest build to the astronaut and he’ll be coming home. A job well done!

Where to Go From Here?

You can download the completed version of the project using the Download Materials button at the top or bottom of this tutorial.

Aside from bringing a stranded astronaut home, you’ve learned a lot about the basic features of IGListKit: section controllers, adapters and how to bring them all together. There are other important features in IGListKit like supplementary views and display events.

You can read and watch more about the origin of IGListKit at Instagram from a talk published by Realm. This talk covers a lot of the common UICollectionView problems that apps experience as they get larger and more complex.

If you’re interested in helping contribute to IGListKit, the team set up starter-task tags on GitHub for an easy way to get started.

If you have any questions or comments about this tutorial or working with IGListKit in general, please join the forum discussion below!