title: Stacking views programmatically in UIStackView
body: <p>I have spent a long time trying to stack the views that I create programmatically. I looked at examples from <a href="https://stackoverflow.com/questions/30728062/add-views-in-uistackview-programmatically">Add views in UIStackView programmatically</a> but that didn't work. Listed below is the code, I am calling the <code>setUpListings</code> from the view controller. There are two entries but only one entry is shown.</p>
  
  <pre><code>import UIKit
  import SnapKit
  
  class ListingsView : UIView {
      var containerView: UIView!
      var listingsContainerView: UIStackView!
  
      init() {
          super.init(frame: CGRect.zero)
          setUpContainerView()
          setUpListingsContainer()
      }
  
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
      }
  
      func setUpContainerView() {
          containerView = UIView()
  
          self.addSubview(containerView)
  
          containerView.snp.makeConstraints { (make) in
              make.height.equalTo(self)
              make.width.equalTo(self)
  
              containerView.backgroundColor = UIColor.white
          }
      }
  
      func setUpListingsContainer() {
          listingsContainerView = UIStackView()
          listingsContainerView.distribution = .equalSpacing
          listingsContainerView.alignment = .fill
          listingsContainerView.axis = .vertical
          listingsContainerView.spacing = 10
          listingsContainerView.translatesAutoresizingMaskIntoConstraints = false
  
          containerView.addSubview(listingsContainerView)
  
          listingsContainerView.snp.makeConstraints { (make) in
              make.top.equalTo(containerView)
              make.left.equalTo(containerView)
              make.bottom.equalTo(containerView)
              make.right.equalTo(containerView)
          }
      }
  
      func setUpListings(listings: [Listing]) {
          for listing in listings {
              let listingEntry = ListingEntry(listingId: listing.id)
              listingsContainerView.addArrangedSubview(listingEntry)
          }
      }
  
      class ListingEntry : UIView {
          var listingId: String?
          var containerView: UIView!
  
          init(listingId: String) {
              super.init(frame: CGRect.zero)
              self.listingId = listingId
              self.setUpContainerView()
          }
  
          required init?(coder aDecoder: NSCoder) {
              super.init(coder: aDecoder)
          }
  
          func setUpContainerView() {
              containerView = UIView()
              containerView.backgroundColor = UIColor.gray
              self.addSubview(containerView)
  
              containerView.snp.makeConstraints { (make) in
                  make.width.equalTo(150)
                  make.height.equalTo(150)
              }
          }
      }
  }
  
  </code></pre>
  
  <p>The view currently looks like
  <a href="https://i.stack.imgur.com/QiYGE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QiYGE.png" alt="enter image description here"></a></p>
  
  <p>But the blocks should be stacked.</p>