Why does UIViewControllerContextTransitioning return optionals?

237 Views Asked by At

When is it possible for this method of UIViewControllerContextTransitioning to return nil?

viewController(forKey key: UITransitionContextViewControllerKey) -> UIViewController?` method of `UIViewControllerContextTransitioning

If it is possible, how should you handle that? Can you somehow default to the system transition if you can't retrieve a view controller involved in the animation? I've been assuming that force unwrapping these values is safe.

1

There are 1 best solutions below

1
Duncan C On

If you read the docs on that call, they say:

Return Value

The view controller object for the specified key or nil if the view controller could not be found.

So if there is no view controller object for the specified key you'll get nil.