title: How to blur an existing image in a UIImageView with Swift?
body: <p>The setup is simple. </p>
  
  <ul>
  <li>A ViewController with UIImageView that has an image assigned. </li>
  <li>A UIButton that when clicked blurs the image in the UIImageView.</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/Yhfgr.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Yhfgr.png" alt="Storyboard"></a></p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
      @IBOutlet weak var bg: UIImageView!
  
      @IBAction func blur(_ sender: Any) {
          let inputImage = CIImage(cgImage: (bg.image?.cgImage)!)
  
          let filter = CIFilter(name: "CIGaussianBlur")
          filter?.setValue(inputImage, forKey: "inputImage")
          filter?.setValue(10, forKey: "inputRadius")
          let blurred = filter?.outputImage
          bg.image = UIImage(ciImage: blurred!)
      }
  }
  </code></pre>
  
  <p>When the button is clicked the screen just turns white. Can't figure out what I'm doing wrong. Anyone know what I'm doing wrong?</p>