title: Replicator will crash when using view layer in xib file?
body: <p><a href="https://i.stack.imgur.com/aqTsw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aqTsw.png" alt="I want to make some thing like this with Replicator (image view and replicate that behind the imageview"></a></p>
  
  <p>so I used a xib file and put image view in that xib file I put the view(perspectiveView) and put the image view in that view and I want to replicate perspective view so here is my codes in UIView file that is xib file class </p>
  
  <pre><code>import UIKit
  
  class perspectiveView: UIView {
  
  
  @IBOutlet var contentView: UIView!
  
  @IBOutlet weak var perspectiveTitle: UILabel!
  
  @IBOutlet weak var perspectiveView: UIView!
  
  @IBOutlet weak var perspectiveImage: UIImageView!
  
  override init(frame: CGRect) {
      super.init(frame: frame)
  
      commonInit()
  }
  
  
  override func layoutSubviews() {
      super.layoutSubviews()
      let replicatorLayer = CAReplicatorLayer()
      let coloredSquare = CALayer()
      //  coloredSquare.backgroundColor = UIColor.red.cgColor
      coloredSquare.frame = perspectiveView.bounds
      coloredSquare.contents = perspectiveView.asImage().cgImage
  
      let instanceCount = 3
      replicatorLayer.instanceCount = instanceCount
      replicatorLayer.instanceTransform = CATransform3DMakeTranslation(5, -10, -1)
      replicatorLayer.instanceAlphaOffset = -0.3
      replicatorLayer.addSublayer(coloredSquare)
      perspectiveView.layer.addSublayer(replicatorLayer)
  }
  
  required public init?(coder aDecoder: NSCoder) {
      super.init(coder: aDecoder)
  
      commonInit()
  }
  
  
  private func commonInit() {
      Bundle.main.loadNibNamed("perspectiveView", owner: self, options: nil)
      addSubview(contentView)
      contentView.frame = self.bounds
      contentView.autoresizingMask = [.flexibleHeight , .flexibleWidth]
  
  }
  
  }
  
  extension UIView {
  // Using a function since `var image` might conflict with an existing variable
  // (like on `UIImageView`)
  func asImage() -&gt; UIImage {
      let renderer = UIGraphicsImageRenderer(bounds: bounds)
      return renderer.image { rendererContext in
          layer.render(in: rendererContext.cgContext)
      }
  }
  }
  </code></pre>
  
  <p>so this will work but not as I expected</p>