---
title: "stackView(_:willDetach:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsstackviewdelegate/stackview(_:willdetach:)"
---

# stackView(_:willDetach:)

Called when the stack view is about to automatically detach one or more of its views.

## Declaration

```swift
@MainActor optional func stackView(_ stackView: NSStackView, willDetach views: [NSView])
```

## Parameters

- `stackView`: The stack view that is about to detach one or more of its views.
- `views`: An array of one or more views, managed by the stack view, that are about to be automatically detached.

## Discussion

Discussion To configure a custom class to respond to the automatic detachment of views from a stack view’s view hierarchy, implement this method in the class. This method is not called when your code explicitly removes a view from a stack view’s views array.

## See Also

### Responding to View Detachment and Reattachment

- [stackView(_:didReattach:)](appkit/nsstackviewdelegate/stackview(_:didreattach:).md)
