title: Swift: UICollectionView sizeForItemAt will never be executed
body: <p>I'm making a CollectionView which has 2 sections, everything is fine but the size. I'd like to give different size of cell in different section, but when I call sizeForItemAt, Xcode shows a  yellow warning &quot;Will never be executed&quot;. Here's how I set my CollectionView functions:</p>
  <pre><code>extension ArtistProfileViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
  
  func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
      return 2
  }
  
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      switch mySections[section] {
      case .profile:
          return 1
      case .relatedArtists:
          return 10
      }
  }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      switch mySections[indexPath.section] {
      case .profile:
          guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ArtistProfileCell.identifier, for: indexPath) as? ArtistProfileCell else { return UICollectionViewCell()}
          
          return cell
      case .relatedArtists:
          guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: RelatedArtistCell.identifier, for: indexPath) as? RelatedArtistCell else { return UICollectionViewCell()}
          cell.myImageView.image = UIImage(systemName: &quot;person&quot;)
          return cell
      }
      
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
            return CGSize(width: 100, height: 100)
         }
  }
  </code></pre>
  <p>And here is how I set my CollectionView:</p>
  <pre><code>    var myCollectionView: UICollectionView = {
      
      let layout = UICollectionViewFlowLayout()
      layout.scrollDirection = .vertical
      layout.estimatedItemSize = .zero
      
      let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
      cv.register(ArtistProfileCell.self, forCellWithReuseIdentifier: ArtistProfileCell.identifier)
      cv.register(RelatedArtistCell.self, forCellWithReuseIdentifier: RelatedArtistCell.identifier)
      
      return cv
  }()
  </code></pre>
  <p>I did set the CollectionView.delegate/datasource to self in viewDidLoad, and I can see the cell appear on the screen. However, the size of cell does not change at all. Plus, I know one of the solution is to set the estimated size to none in storyboard, but I don't know how to set it programmatically. So I don't know if it works.</p>
  <p>There's one thing odd, when I call sizeForItemAt, it does not show the complete function automatically. I have to type it by myself like <a href="https://i.stack.imgur.com/farvB.png" rel="nofollow noreferrer">this</a>.</p>
  <p>Does anyone can help? Thanks in advance!</p>