title: Why does CABasicAnimation try to initialize another instance of my custom CALayer?
body: <p>I get this error:</p>
  
  <blockquote>
    <p>fatal error: use of unimplemented initializer 'init(layer:)' for class 'MyProject.AccordionLayer'</p>
  </blockquote>
  
  <p>using the following code. In my view controller:</p>
  
  <pre><code>override func viewDidLoad() {
      let view = self.view as! AccordionView!
      view.launchInitializationAnimations()
  }
  </code></pre>
  
  <p>In my view:</p>
  
  <pre><code>required init(coder aDecoder: NSCoder) {
      super.init(coder: aDecoder)
  
      for var i = 0; i &lt; self.accordions.count; ++i {
          var layer = AccordionLayer(accordion: self.accordions[i])
          layer.accordion = self.accordions[i]
          layer.frame = CGRectMake(0, CGFloat(i) * self.getDefaultHeight(), self.frame.width, self.getDefaultHeight())
          self.layer.addSublayer(layer)
          layer.setNeedsDisplay()
          layers.append(layer)
      }
  }
  
  func launchInitializationAnimations() {
      for layer in self.layer.sublayers {
          var animation = CABasicAnimation(keyPath: "topX")
          animation.duration = 2.0
          animation.fromValue = CGFloat(0.0)
          animation.toValue = CGFloat(200.0)
          layer.addAnimation(animation, forKey: "animateTopX")
      }
  }
  </code></pre>
  
  <p>And in my subclassed CALayer</p>
  
  <pre><code>var topX : Int
  init(accordion: (color: CGColorRef!, header: String, subtitle: String, image: UIImage?)!) {
  
      // Some initializations
      // ...
  
      super.init()
  }
  </code></pre>
  
  <p>I also implement <code>needsDisplayForKey</code>, <code>drawInContext</code>.</p>
  
  <p>I have seen 2-3 other questions with the same error message but I can't really figure out how it is related to my specific case on my own.</p>
  
  <p>Why is <code>CABasicAnimation</code> trying to instantiate a new (my custom) CALayer?</p>