One of the common developments in mobile applications is showing information using tables. This task can easily be done when you have a collection of homogeneous entities, but it gets trickier when this collection has n-number of different entities. In this article, I’m going to show an example of how to display heterogeneous data in a table view using the adapter pattern. The example exposed is a messaging app with two types of messages; texts and images. 

Display Heterogeneous Data in a Table View

When we face the problem of displaying heterogeneous data in tables, the straightforward solution is to use pattern matching in the method “cellForRowAtIndexPath” to decide what cell we need to use to display the current entity in the collection.

One of the common developments in mobile applications is showing information using tables. This task can easily be done when you have a collection of homogeneous entities, but it gets trickier when this collection has n-number of different entities. In this article, I’m going to show an example of how to display heterogeneous data in a table view using the adapter pattern. The example exposed is a messaging app with two types of messages; texts and images. 
Display Heterogeneous Data in a Table View
When we face the problem of displaying heterogeneous data in tables, the straightforward solution is to use pattern matching in the method “cellForRowAtIndexPath” to decide what cell we need to use to display the current entity in the collection. […]