UICollectionView/Layout, dynamic cell size with AutoLayout

I’m trying to develope a custom UICollectionView/Layout which needs to layout cells in a vertical stack (like a table), but which displays cell whose size (height in particular) is dynamic and whose layout is managed by Autolayout.

While there are some common cells, many of the cells are one offs, displaying particular information about the state of the system I’m coding against.

Cells may also dynamically change size depending on user interaction.

I’ve been looking at as many tutorials as I can, but I’ve not found any which seems to be able to calculate the content height based on this dynamic nature of the layout.

I’ve been looking back through the Pintrest tutorial, but I’m not sure if I can use it that technique, as I’d still need to dequeue the cells in order to be able to calculate the cell size, unless I generate a cache of my own, which seems like a bad idea.

I tried dequeuing the cells in the UICollectionViewLayout.prepare method, but that leads to a recursive call and a stackoverflow crash.

This is obviously a lack of knowledge with how the layout is suppose to work, but I can’t seem to find an answer to the problem.

Any suggestions (tutorials, sample code, videos, etc) would be most greatful