<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIViewControllerTransitionCoordinatorContext/viewController(forKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UIViewControllerTransitionCoordinatorContext(im)viewControllerForKey:"
  },
  "title" : "viewController(forKey:)"
}
-->

# viewController(forKey:)

Returns the view controllers involved in the transition.

```
func viewController(forKey key: UITransitionContextViewControllerKey) -> UIViewController?
```

## Parameters

`key`

The key indicating which view controller you want. For a list of possible values, see [`UITransitionContextViewControllerKey`](/documentation/UIKit/UITransitionContextViewControllerKey).

## Return Value

The view controller associated with the key.

## Discussion

The view controller associated with the [`from`](/documentation/UIKit/UITransitionContextViewControllerKey/from) key corresponds to the view controller that’s already onscreen. The view controller associated with the [`to`](/documentation/UIKit/UITransitionContextViewControllerKey/to) key corresponds to the view controller that’s to be animated onscreen.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)