Can't call IBOutlet properties in function

hello, i’m working in swift and i’m trying to use the .frames to check if 2 objects of type CGRect intersect.
i have my View Controller Class and a CircleClass, the CircleClass creates a circle that has gesture recognition so i can drag the circles that i create where i want to, now i want to add the option that if at the end of the drag the subview intersects my trashimageView (that has the image o a trashcan) it can delete the circle or subView.

the problem is that when i try to call trashImageView.frame in a function “deleteSubView” that i’ve created in the View Controller i get nil and my app crashes, but if the IBOutlet is in the VC and my function is also defined in my VC, also i can call the trashImageView.frame in the viewDidLoad and there is fine, but not in my function, why do i get nil for this value??

are you sure trasImageView IBOutlet has been set properly?, or maybe you somehow “overwritten” it during function call

try posting the code so we can see it

the IBOutlet is good, it works in the viewDidLoad function, here’s my code

class ViewController: UIViewController {

@IBOutlet var trashImageView: UIImageView!

override func viewDidLoad() {
    super.viewDidLoad()
    
    let tapGR = UITapGestureRecognizer(target: self, action: #selector(ViewController.didTap))
    
    self.view.addGestureRecognizer(tapGR)
    
    //here the CGRect prints just fine
    print("my imageView init: \(trashImageView.frame)")

}

func deleteSubView(subView: UIView){

    // Here i get nil from the trashImageView.frame
    if (subView.frame.intersects(trashImageView.frame)) {
        print("intersection")
        subView.removeFromSuperview()
    }
}

}
i call the function ‘delete subView’ from another class but should that matter? i don’t understand what is the error here, help please

thats wierd. can you try moving the print statement to the start of your deleteSubView function to see if it works there?
if it does then maybe subView.frame.intersects is the problem