title: How to remove gradient layer in swift
body: <pre><code>Code:
  
      extension CAGradientLayer
      {
          func changeStatusBarColor() -&gt; CAGradientLayer
          {
              var height = 20
              let Size = UIScreen.main.bounds
  
              let darkViolet = UIColor(hexString: "#44377D")
              let lightViolet = UIColor(hexString: "##686CCD")
  
              let gradientLayer = CAGradientLayer()
              gradientLayer.frame = CGRect(x: 0, y: 0, width:Int(Size.width), height: height)
              gradientLayer.colors =  [darkViolet,lightViolet ].map{$0.cgColor}
              gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5)
              gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5)
              return gradientLayer
          }
      }
  
       let gradientLayer = CAGradientLayer()
              gradientLayer.name = "masklayer"
              self.view.layer.addSublayer(gradientLayer.changeStatusBarColor())
  
              for layer in self.view.layer.sublayers! {
                  print("layer name:", layer.name)
                  if layer.name == "masklayer" {
                      layer.removeFromSuperlayer()
                  }
              }
  </code></pre>
  
  <p>I applied gradient colour for status bar.when I tried to remove sublayer  with above code it does not remove sublayer.what is wrong with my code.any help will be appreicated.thanks in advance</p>