title: How to add gradient to UIView as an extension
body: <p>I am trying to add some gradient to a view in Xcode and for simplicity I tried to add my method as an extension to UIView:</p>
  
  <pre><code>extension UIView {
      func applyGradient() {
          let gradient = CAGradientLayer()
          gradient.colors = [UIColor(hex: "F5FF8C").cgColor,
                             UIColor(hex: "F1F99D").cgColor,
                             UIColor(hex: "FDFFE0").cgColor]
          gradient.locations = [0.0, 0.5, 1.0]
  
          self.layer.insertSublayer(gradient, at: 0)
      }
  }
  </code></pre>
  
  <p>But apparently this doesn't work when I call it in my <code>viewDidLoad</code>:</p>
  
  <pre><code>self.myView.applyGradient()
  </code></pre>
  
  <p>Can someone point to me what am I doing wrong ? </p>