title: Should I use dynamic stackview inside UITableViewCell or use UICollectionView?
body: <p><a href="https://i.stack.imgur.com/ubxge.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ubxge.png" alt="enter image description here" /></a></p>
  <p>Hello. I am building flights booking app, which has complex UITableViewCell. Basically, it is simple card with shadow, that has bunch of stackviews. First stackview, you see it on image is for labels. It is horizontal and dynamic. The next stackview shows flights. It has complex custom view, but for the sake of simplicity, it is shown with green border. It is also dynamic, so I need separate stackview for it. The next stackview is for airline companies that can handle this booking. I call them as operators. It is also dynamic, so I build yet another stackview for them. And of all these stack views are inside some core stackview. You can ask, why I created separate stack views instead of one? Because, labels above can be hidden. And also spacing in all stackviews are different.</p>
  <ol>
  <li><p>It is really complex design. I followed above approach and build UITableViewCell. But performance is really bad. The reason is simple: I do too many stuff in cellForRowAt. The <code>configure</code> method of UITableViewCell is called everytime when the cell is dequeued. It means I should clean my stackview every time and after only that, append my views. I think it is really affects performance. I don't tell about other if/else statements inside cell. The first question is how can I increase scrolling performance of UITableViewCell in this case?</p>
  </li>
  <li><p>Some developers reckons that UITableView should be killed. UICollectionView rules the world. OK, but can I use UICollectionView with this design? Yes, of course, but above card would be one UICollectionViewCell and I simply don't avoid problem. The another solution is to build separate UICollectionViewCell for label (see on image), flight and operator. This would definitely increase performance. But, how can I make all of them live inside card?</p>
  </li>
  </ol>
  <p>P.S. What is inside my cellForRowAt method? There is only one <code>configure</code> method and assigning values to closure. But configure method is pretty complex. It gets some protocol which has bunch of computed properties. I pass implementation of that protocol to <code>configure</code> method. Protocol is like this:</p>
  <pre><code>protocol Booking {
    var flights: [Flight] { get }
    var operators: [Operator] { get }
    var labels: [Label] { get }
    var isExpanded: Bool { get set }
  }
  </code></pre>
  <p>Implementation of this protocol is also complex. There are bunch of map functions and if/else statements. Some string manipulations. So, does that cause a problem? How can I solve it? By avoiding properties to be computed and just pass properties(flights, operators) to the implementation?</p>