---
title: layoutSubtreeIfNeeded()
framework: appkit
role: symbol
role_heading: Instance Method
path: appkit/nsview/layoutsubtreeifneeded()
---

# layoutSubtreeIfNeeded()

Updates the layout of the receiving view and its subviews based on the current views and constraints.

## Declaration

```swift
func layoutSubtreeIfNeeded()
```

## Discussion

Discussion Before displaying a view that uses constraints-based layout the system invokes this method to ensure that the layout of the view and its subviews is up to date. This method updates the layout if needed, first invoking updateConstraintsForSubtreeIfNeeded() to ensure that all constraints are up to date. This method is called automatically by the system, but may be invoked manually if you need to examine the most up to date layout. Subclasses should not override this method.

## See Also

### Triggering Auto Layout

- [needsLayout](appkit/nsview/needslayout.md)
- [layout()](appkit/nsview/layout().md)
- [needsUpdateConstraints](appkit/nsview/needsupdateconstraints.md)
- [updateConstraints()](appkit/nsview/updateconstraints().md)
- [updateConstraintsForSubtreeIfNeeded()](appkit/nsview/updateconstraintsforsubtreeifneeded().md)
