Yes you’re right, the animator crashes because it tried to unwrap a view which is not available anymore.
toView which you used during the presentation actually becomes a
fromView during dismissal.
It was used earlier in the tutorial but is actually not needed at the end because we’re using
To fix it you can simply remove the property
toView and incorporate it into
recipeView like so:
let containerView = transitionContext.containerView
let recipeView = presenting ? transitionContext.view(forKey: .to)! : transitionContext.view(forKey: .from)!
Note how the faulty line has been removed in the middle an added in
Doing this will trigger another error a bit further in the method as it’s trying to add
toView as subview, which is not possible because we juste removed it. Lucky for us we incorporated it in
recipeView so you can add that one instead:
Tadaa, the whole shebang should work again!
Enjoy your new animation!