title: How to init collectionViewCell with image without Storyboard or nib?
body: <p>How to init collection view Cell with image without Storyboard or nib ?</p>
  
  <p>I'm building ImagePicker and want to do it without storyboards</p>
  
  <p>so the working code with storyboard is like that, but how to do it programmatically ?</p>
  
  <pre><code>class PhotosCollectionViewCell: UICollectionViewCell {
      @IBOutlet weak var imageView: UIImageView!
  
      var image: UIImage? {
          get { return imageView.image }
          set { imageView.image = newValue }
      }
  
      override func prepareForReuse() {
          super.prepareForReuse()
          self.imageView.image = nil
      }
  
  }
  </code></pre>
  
  <p>My changed code without IBOutlet:</p>
  
  <pre><code>class PhotosCollectionViewCell: UICollectionViewCell {
      var imageView: UIImageView!
      public var asset: PHAsset!
      public var cellTappedAction: ((PHAsset) -&gt; ()) = { _ in }
  
      var image: UIImage? {
          get { return imageView.image }
          set { imageView.image = newValue }
      }
  
      override init(frame: CGRect) {
        self.imageView = UIImageView()
        super.init(frame: frame)
          self.imageView.image = self.image
          self.imageView.frame = self.frame
          self.addSubview(self.imageView)
      }
  
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
  //        fatalError("init(coder:) has not been implemented")
      }
  
      override func prepareForReuse() {
          super.prepareForReuse()
          self.imageView.image = nil
      }
  }
  </code></pre>
  
  <p>Controller: </p>
  
  <pre><code>self.collectionView?.register(PhotosCollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
  </code></pre>
  
  <p>So the first picture without IBOutlet and the second one with it </p>
  
  <p><a href="https://i.stack.imgur.com/DfXQC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DfXQC.png" alt="Non storyboard cell"></a>
  <a href="https://i.stack.imgur.com/Tkz4w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tkz4w.png" alt="storyboard cell"></a></p>