title: In which method of a UICollectionViewCell should I write code to only run once?
body: <p>I am looking to modify a <code>UICollectionView</code>'s layout just after it has set its <code>imageView.image</code>.</p>
  
  <p>I want to know the correct way to execute my code only once for my reusable cell.</p>
  
  <p>So far, the method that works for me was to draw my custom views inside it in the <code>cellForRow()</code> method, but it makes the code messy. I would like to execute the code inside the cell's class. </p>
  
  <p><code>Init</code> (with frame) didn't work. It wasn't even called from my <code>collectionView</code>.</p>
  
  <p>Moreover, if somebody can give me a fast explanation of what the most important methods of a <code>UICollectionViewCell</code> do and when to use each one of them, I would appreciate!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This is the code I want to remove from <code>cellForRow()</code> and move into the cell's class:</p>
  
  <pre><code>firstProductCell.imageView.image = UIImage(named: "photo1")
  firstProductCell.textLabel.text = "Featured title"
  
  let imgview: UIImageView = UIImageView(frame: CGRectMake(0, 0, 1100, 600))
  imgview.image = firstProductCell.imageView.image
  
  let whiteView: UIView = UIView(frame: CGRectMake(1200, 0, 600, 600))
  whiteView.backgroundColor = UIColor.whiteColor()
  
  let view: UIView = UIView(frame: cell.bounds)
  view.addSubview(imgview)
  view.addSubview(whiteView)
  
  UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0)
  view.layer.renderInContext(UIGraphicsGetCurrentContext()!)
  firstProductCell.imageView.image = UIGraphicsGetImageFromCurrentImageContext()
  UIGraphicsEndImageContext()
  </code></pre>