How do you get an override function to be called on command?

I have a function:

override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {

        print("Layout has been changed.")

        let targetSize = CGSize(width: layoutAttributes.frame.width, height: 40)

        layoutAttributes.frame.size = contentView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)

        return layoutAttributes

    }

This function changes the frame of my UICollectionViewCells and it is working exactly how it is supposed to.

The problem is that this function is only called when the view loads for the first time, but when I call reloadData() on my collectionView this function is not called. Because this function is not called it screws up the sizes of my collectionView.

My question is how do I get this function to run when I call reloadData() on my collectionView?

How do you get an override function to be called on command?
 
 
Q