How could a print statement removal break my project? (Swift/Xcode)

Viewed 122

If I so much as comment out the print line, everything in toVC fails to load. Every element of toVC is nil. If I leave the print statement everything works as intended. Why?

I am in a UITabBarControllerDelegate's animationControllerForTransitionFrom method if that helps anything.

I have never had anything like this happen before. As soon as I remove the line, it breaks the first time I touch any element attached with an IBOutlet. Any help will be greatly appreciated.

func animateToProfile(using transitionContext: UIViewControllerContextTransitioning) {
    guard let fromVC = transitionContext.viewController(forKey: .from)?.childViewControllers.first,
        let toVC = transitionContext.viewController(forKey: .to)?.childViewControllers.first as? ProfileViewController,
        let superviewToAdd = toVC.parent?.view else { return }

    print("\(toVC.view.frame)")

    let sideMenuOriginX = UIScreen.main.bounds.width * (98 / 414)

    toVC.sideMenuView.frame.origin.x = toVC.view.frame.width
    toVC.visualEffectView.alpha = 0

    transitionContext.containerView.addSubview(superviewToAdd)

    let duration = transitionDuration(using: transitionContext)

    UIView.animate(withDuration: duration, delay: 0, options: [.curveEaseInOut], animations: {
        toVC.sideMenuView.frame.origin.x = sideMenuOriginX
        toVC.visualEffectView.alpha = 1
    }, completion: { _ in
        transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
    })
}
1 Answers
Related