---
title: "insertViewController(_:at:animated:)"
framework: CareKit
role: symbol
role_heading: Instance Method
platforms: [iOS 13.0+, Mac Catalyst 13.0+, watchOS 7.0+]
path: "carekit/ocklistviewcontroller/insertviewcontroller(_:at:animated:)"
---

# insertViewController(_:at:animated:)

Inserts a view controllers view at a specific index, and sets up containment for the view controller.

## Declaration

```swift
func insertViewController(_ viewController: UIViewController, at index: Int, animated: Bool)
```

## Parameters

- `viewController`: The view controller with the view that you insert. If the view controller is the child of a container view controller, the list view controller removes it from that container before it inserts the view controller.
- `index`: The index at which to insert the viewController’s view. This value must not be greater than the number of views in the OCKListViewController. If the index is out of bounds, this method throws an https://developer.apple.com/documentation/foundation/nsexceptionname/1416220-internalinconsistencyexception/ exception.
- `animated`: A Boolean value that indicates whether to animate the insertion of the view controller.

## See Also

### Inserting in the list

- [insertView(_:at:animated:)](carekit/ocklistviewcontroller/insertview(_:at:animated:).md)
