The project is open source, and here is the link: https://github.com/jeantimex/ios-swift-collapsible-table-section
In this project, the table view automatically resizes the height of the rows to fit the content in each cell, and the custom cell is also implemented programmatically.
Also, a cocoapod is available here: https://github.com/jeantimex/CollapsibleTableSectionViewController.
I am planning to upgrade the project to swift 4.
Best, jeantimex