[Swift] FlexibleTableViewController

Dmytro Pylypenko
1 min readMar 29, 2015

--

I decided to publish the development of TableViewController related to my needs. I’m confident someone will find it useful!

But before, I would like to tell you a little about its development.
The main thing is reusing for different cases or in other words, abstraction. So I will use generics for it. First for cell data, second, optional, for a generator which serves to section generation.

As Swift does not support generic subclass on non-generic class, I’ve bypass this using a wrapper. With a simple manipulation of protocols and generic classes, table becomes abstract, especially in view of external processing of basic things. There are:

var requestCellIdentifier: (NSIndexPath -> String?)?
var configureCell: ((UITableViewCell, T?) -> Bool)?
var cellDidSelect: (NSIndexPath -> Bool)?

It also takes configuration data, the example below illustrates this with initialization with generics:

let flexibleTableVC = FlexibleTableViewController<CustomCellData, OrderedListGenerator<CustomCellData>>(style: .Plain, configuration: TableConfiguation())

Updated to Swift 2.
The full code with example of usage is on GitHub: http://github.com/dimpiax/FlexibleTableViewController

--

--