Not so long ago I’ve published an article called “Forget datasource & delegate: a new approach to UITableView“; the title may appear as a bit pretentious but, believe me when I say I’m tired to fill-up datasource and delegates methods placeholders just to make a simple (or complex) table/collection.

I do not want to bore you with yet another article about massive view controllers but the whole thing is easy to become a big jumble when you want to implement some business logic and flexible rendering to represented data.

My first attempt to approach this problem ended in Flow, a little but useful utility which allows you to create and manage the content of a table in a declarative way. I liked it so much and I’m still using it in different production projects with success; however, as often happens in this work, time, attempts, failures and, in a single word, experiences helped me to better understand the problem, the implications of my solution by giving to you the opportunity to improve my original work.

The following article recounts the story behind the original idea and propose a new improved approach you can use both for UITableView and UICollectionView.

View the article

TableViews are everywhere; for years before the introduction of Collection Views they were one of the fundamental block of every application’s.

Even if now we are able to replace the entire functionality with the combo of UICollectionView  & UICollectionViewFlowLayout  (take a look at “The case for deprecating UITableView) they still play a key role during the everyday work life of any iOS developers.

Frankly I always hated the way in which we prepare and manage contents inside table for several different reasons:

  • tons of boilerplate code to declare data source & delegates. I loved the datasource/delegate pattern, but we can do better and we can do it in Swift, of course.
  • it’s weak: declare cell via identifiers (literals!), cast and finally use them; in our new strong-typed world this is a nightmare we need to avoid.
  • complex tables are a nightmare to prepare and manage; usually you will end up in a world full of if/switch conditions to allocate one cell instead of another, do an action if the you tapped this or another cell and so on. I just want to declare content and do actions.
  • Your view controllers are easy to become full of apparently-non-sense-conditions used to manage the content of your tables.
View the article