<!--
{
  "availability" : [
    "macOS: 10.10.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSViewController/insertChild(_:at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSViewController(im)insertChildViewController:atIndex:"
  },
  "title" : "insertChild(_:at:)"
}
-->

# insertChild(_:at:)

Inserts a specified child view controller into the [`children`](/documentation/AppKit/NSViewController/children) array at a specified position.

```
func insertChild(_ childViewController: NSViewController, at index: Int)
```

## Parameters

`childViewController`

The child view controller to add to the [`children`](/documentation/AppKit/NSViewController/children) array.

`index`

The index in the [`children`](/documentation/AppKit/NSViewController/children) array at which to insert the child view controller. This value must not be greater than the count of elements in the array.

## Discussion

You should instead use the [`addChild(_:)`](/documentation/AppKit/NSViewController/addChild(_:)) method unless you want to perform work on child view controllers as you add them. In that case, override this method to perform that work.

If a child view controller has a different parent when you call this method, the child is first be removed from its existing parent by calling the child’s [`removeFromParent()`](/documentation/AppKit/NSViewController/removeFromParent()) method.

---

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)