I can't show QR in Image View

Hi everyone, i need your help please, i have a code that generates a QR when you push a button and shows the generated QR in an Image View, it works in the simulator but when i connect my iphone and test my code instead of the QR it shows a black square, but in the console there aren't any errors.
Also, when I put the code that generates the QR in the viewDidLoad() function instead of the Button function, it works ok in my iphone.

Im sure that the QR its being generated because I have a sharing button and when I push it and share the QR it does share it just fine, the QR shows correctly.

Here is my code, the one that generates and shows the QR.

Code Block
@IBAction func VerQR(_ sender: Any) {
    if idQr != nil{
      let residente = "3473532/MY/" + idQr
      let data = residente.data(using: .ascii, allowLossyConversion: false)
      filter = CIFilter(name: "CIQRCodeGenerator")
      filter.setValue(data, forKey: "inputMessage")
      let transform = CGAffineTransform(scaleX: 10, y: 10)
      let image = UIImage(ciImage: filter.outputImage!.transformed(by: transform))
      imagenQR.image = image
    }
  }

Here is the code that shares the QR
Code Block
@IBAction func compartirBtn(_ sender: UIButton) {
      let image = imagenQR.image
      let imageToShare = [image!]
      let activityViewController = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
      activityViewController.popoverPresentationController?.sourceView = self.view
      self.present(activityViewController, animated: true, completion: nil)


Can you show a complete code to reproduce the issue?
Minimized would be preferable, but currently shown code lacks many parts and I cannot test it.
What is idQr ? How is it set ?

Could you test with a print on line 2 of VerQR that it is not nil ?

What doesn't work ? Is it compartirBtn or VerQR ?
I can't show QR in Image View
 
 
Q