---
title: "viewWillDisappear(_:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/uihostingcontroller/viewwilldisappear(_:)"
---

# viewWillDisappear(_:)

Notifies the view controller that its view will be removed from a view hierarchy.

## Declaration

```swift
@MainActor @preconcurrency override dynamic func viewWillDisappear(_ animated: Bool)
```

## Parameters

- `animated`: If true, the view is being removed using an animation.

## Discussion

Discussion SwiftUI calls this method before removing the hosting controller’s root view from the view hierarchy. You can override this method to perform custom tasks associated with the disappearance of the view. If you override this method, you must call super at some point in your implementation.

## See Also

### Responding to view-related events

- [loadView()](swiftui/uihostingcontroller/loadview().md)
- [viewWillAppear(_:)](swiftui/uihostingcontroller/viewwillappear(_:).md)
- [viewDidAppear(_:)](swiftui/uihostingcontroller/viewdidappear(_:).md)
- [viewDidDisappear(_:)](swiftui/uihostingcontroller/viewdiddisappear(_:).md)
- [willMove(toParent:)](swiftui/uihostingcontroller/willmove(toparent:).md)
- [didMove(toParent:)](swiftui/uihostingcontroller/didmove(toparent:).md)
- [viewWillTransition(to:with:)](swiftui/uihostingcontroller/viewwilltransition(to:with:).md)
- [viewWillLayoutSubviews()](swiftui/uihostingcontroller/viewwilllayoutsubviews().md)
- [target(forAction:withSender:)](swiftui/uihostingcontroller/target(foraction:withsender:).md)
- [rootView](swiftui/uihostingcontroller/rootview.md)
