---
title: "viewController(forKey:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiviewcontrollertransitioncoordinatorcontext/viewcontroller(forkey:)"
---

# viewController(forKey:)

Returns the view controllers involved in the transition.

## Declaration

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

## Parameters

- `key`: The key indicating which view controller you want. For a list of possible values, see doc://com.apple.uikit/documentation/UIKit/UITransitionContextViewControllerKey.

## Return Value

Return Value The view controller associated with the key.

## Discussion

Discussion The view controller associated with the from key corresponds to the view controller that’s already onscreen. The view controller associated with the to key corresponds to the view controller that’s to be animated onscreen.

## See Also

### Getting the views and view controllers

- [view(forKey:)](uikit/uiviewcontrollertransitioncoordinatorcontext/view(forkey:).md)
- [containerView](uikit/uiviewcontrollertransitioncoordinatorcontext/containerview.md)
