title: get all the subviews of a cell onClick in UICollectionView swift
body: <p>I am trying to access all the subviews attached to the cell in <code>UICollectionView</code> when the cell is clicked. </p>
  
  <p>I am able to add the image and label to it, but it shows nil when I tap on any cell</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
    let myCell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath)
  
    // Image      
    let imageview:UIImageView = UIImageView(frame: CGRect(x: 5, y: 5, width: myCell.frame.width - 10, height: myCell.frame.height - 20))
    imageview.image = UIImage(named: String(format: "%@.png", arr[indexPath.row]))
    imageview.tag = 20
  
    // Label
    let label = UILabel(frame: CGRect(x: 5, y: 50, width: myCell.frame.width - 10, height: myCell.frame.height - 40))
    label.textAlignment = .center
    label.text = arr[indexPath.row]
    label.textColor = .black
    label.tag = 21
    label.font = label.font.withSize(8)
  
    myCell.contentView.addSubview(imageview) 
    myCell.contentView.addSubview(label)
  
    myCell.backgroundColor = UIColor.white
  
    return myCell
  }
  </code></pre>
  
  <p>and I am trying to access the subviews as below:</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let myCell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath)
    print(myCell.contentView.subViews) // Returns null
  }
  </code></pre>
  
  <p>I am aware that we can get the item index using <code>indexPath.row</code>. But I want read the subview. How to get it ? Thanks for your help</p>