title: Can I change CAGradientLayer() colors via an IBAction?
body: <p>I have the following extension file defined where I am setting a gradient for my UIView:</p>
  
  <pre><code>import Foundation
  import UIKit
  
  extension UIView {
  
      func setGradientBackground(colorOne: UIColor, colorTwo: UIColor) {
  
          let gradientLayer = CAGradientLayer()
          gradientLayer.frame = bounds
          gradientLayer.colors = [colorOne.blue, colorTwo.red]
          gradientLayer.locations = [0.0, 1.0]
          gradientLayer.startPoint = CGPoint(x: 1.0, y: 1.0)
          gradientLayer.endPoint = CGPoint(x: 0.0, y: 0.0)
          layer.insertSublayer(gradientLayer, at: 0)
      }
  </code></pre>
  
  <p>This links to a separate structs file, where I have defined four <code>UIColor</code>s:</p>
  
  <pre><code>blue,red,black,white
  </code></pre>
  
  <p>My viewcontroller.swift file has the following code within <code>viewDidLoad</code>:</p>
  
  <pre><code>myView.setGradientBackground(colorOne: Colors.blue, colorTwo: Colors.red)
  </code></pre>
  
  <p>This seems to work fine.</p>
  
  <p>What I am trying to achieve is, when I click my <code>IBAction</code> button, it changes the <code>myView</code> colors to black and white (the remaining two colors). So I tried this:</p>
  
  <pre><code>@IBAction func hitButton(_ sender: Any) {
  
      myView.setGradientBackground(colorOne: Colors.black, colorTwo: Colors.white)
  
  }
  </code></pre>
  
  <p>But this causes a crash: "unrecognized selector sent to instance 0x7fb25060a120"</p>