Ver altura dinámica con Swift 3 en iOS

Recientemente, estoy tratando de hacer algunos proyectos para practicar. Así que vi el curso "Desarrollo de aplicaciones para iOS", Universidad de Stanford, CS193P, 2017.

Y ahora, estoy haciendo el proyecto "Smashtag" pero tengo algunos problemas. Quiero usar un CollectionView con dos UICollectionViewFlowLayout para mostrar dos tipos en cada xib (uno es como tableView, otro está mostrando una imagen en cuadrado) de CollectionView por SegmentedControl.

Mis problemas a continuación:

¿Cómo hacer que CollectionViewCell se muestre en altura dinámica al igual que UITableViewAutomaticDimension de TableView?

Y esto es lo que acabo de probar a continuación:

Traté de hacer la configuración de AutoResize de CollectionView como la AutoDimension de TableView con el usoUICollectionViewFlowLayoutAutomaticSize. (@disponible (iOS 10.0, *))

enum CollectionViewType {
  case tweet
  case image
}

// MARK: - Decide What Kind Of FlowLayout
func decideFlowLayout(type: CollectionViewType) -> UICollectionViewFlowLayout {

    // just for .image type
    var howManyImageShowing = 3  
    var imageShowingWidth: Double {
        return Double(self.view.frame.width) / Double(howManyImageShowing)
    }

    // .tweet is a type showing like TableViewCell -> this make me confused !!
    // another type is just showing a image in square -> I have no problem here
    let estimatedItemSize = type == .tweet ? CGSize(width: self.view.frame.width, height: 155.0) :
                                                CGSize(width: imageShowingWidth, height: imageShowingWidth)

    let collectionViewLayout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    collectionViewLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

    // --------- Make this setting as TableView does --------- 
    // ------------ Somethis just like this below ------------
    /*
        tableView.estimatedRowHeight = 155.0
        tableView.rowHeight = UITableViewAutomaticDimension
    */

    collectionViewLayout.estimatedItemSize = estimatedItemSize
    collectionViewLayout.itemSize = UICollectionViewFlowLayoutAutomaticSize
    // ------------------------------------------------------- 

    collectionViewLayout.minimumLineSpacing = 0
    collectionViewLayout.minimumInteritemSpacing = 0

    return collectionViewLayout
}

Restricción de mi CollectionViewCell xib aquí:Pero tiene error cuando ejecuto esta aplicación

No sé lo que echo de menos, entiendo.

¿Por qué funcionará esta solución?

Ya busco tantas soluciones de este problema en Stack Overflow, pero solo encuentro esto y me confunde mucho :(

Esta solución le da a la vista unRestricción de ancho que está en CollectionViewCell xib y establece un valor constante de esta restricción y ¡funciona! No puedo configurar por quéRestricción de ancho hará que la altura de la celda sea dinámica? Esto me confunde mucho, creo que esto es raro ...

https://github.com/tttsunny/CollectionViewAutoSizingTest

class Cell: UICollectionViewCell {
    @IBOutlet weak var headerLabel: UILabel!
    @IBOutlet weak var descriptionLabel: UILabel!
    @IBOutlet weak var widthConstraint: NSLayoutConstraint!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.contentView.translatesAutoresizingMaskIntoConstraints = false
        let screenWidth = UIScreen.main.bounds.size.width
        widthConstraint.constant = screenWidth - (2 * 12)
    }
}

Cómo hacer la altura dinámica de CollectionViewCell sin usarUICollectionViewFlowLayoutAutomaticSize. (@disponible (iOS 10.0, *)) ?

Porque quiero manejar diferentes versiones de iOS no solo en iOS 10 sino también debajo de iOS 10.

Realmente quiero ser profesional en el desarrollo de iOS y un gran desarrollador, pero todavía estoy aprendiendo e intentando. Cualquier respuesta será muy apreciada.

Gracias !!

Respuestas a la pregunta(3)

Su respuesta a la pregunta