<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIViewController/willMove(toParent:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIViewController(im)willMoveToParentViewController:"
  },
  "title" : "willMove(toParent:)"
}
-->

# willMove(toParent:)

Called just before the view controller is added or removed from a container view controller.

```
func willMove(toParent parent: UIViewController?)
```

## Parameters

`parent`

The parent view controller, or `nil` if there is no parent.

## Discussion

Your view controller can override this method when it needs to know that it has been added to a container.

If you are implementing your own container view controller, it must call the [`willMove(toParent:)`](/documentation/UIKit/UIViewController/willMove(toParent:)) method of the child view controller before calling the [`removeFromParent()`](/documentation/UIKit/UIViewController/removeFromParent()) method, passing in a parent value of `nil`.

When your custom container calls the [`addChild(_:)`](/documentation/UIKit/UIViewController/addChild(_:)) method, it automatically calls the [`willMove(toParent:)`](/documentation/UIKit/UIViewController/willMove(toParent:)) method of the view controller to be added as a child before adding it.

---

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)