0

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.

elce
  • 264
  • 4
  • 16
  • I always force unwrap them. – matt May 05 '17 at 22:01
  • Going to keep force unwrapping them, I've never gotten nil from this method in Obj-C or Swift. I suppose that's theoretically possible that the from/to VC could be nil'd out for some awful reason in the middle of a transitioning. And it looks like from here that there was a bug that was causing that to happen. http://stackoverflow.com/questions/24338700/from-view-controller-disappears-using-uiviewcontrollercontexttransitioning But I think that even if it definitely wasn't possible, this API prob isn't pure Swift so it has to return an optional – elce May 07 '17 at 18:39

1 Answers1

0

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.

Duncan C
  • 128,072
  • 22
  • 173
  • 272