---
title: updateConstraints()
framework: appkit
role: symbol
role_heading: Instance Method
path: appkit/nsview/updateconstraints()
---

# updateConstraints()

Update constraints for the view.

## Declaration

```swift
func updateConstraints()
```

## Mentioned in

Updating views automatically with observation tracking

## Discussion

Discussion Override this method to optimize changes to your constraints. note: It is almost always cleaner and easier to update a constraint immediately after the affecting change has occurred. For example, if you want to change a constraint in response to a button press, make that change directly in the button’s action method. You should only override this method when changing constraints in place is too slow, or when a view is producing a number of redundant changes. To schedule a change, set the view’s needsUpdateConstraints property to true. The system then calls your implementation of updateConstraints() before the layout occurs. This lets you verify that all necessary constraints for your content are in place at a time when your custom view’s properties are not changing. Your implementation must be as efficient as possible. Do not deactivate all your constraints, then reactivate the ones you need. Instead, your app must have some way of tracking your constraints, and validating them during each update pass. Only change items that need to be changed. During each update pass, you must ensure that you have the appropriate constraints for the app’s current state. Do not set the needsUpdateConstraints property inside your implementation. Setting needsUpdateConstraints to true schedules another update pass, creating a feedback loop. This method supports automatic observation tracking. For more information, see Updating views automatically with observation tracking. important: Call [super updateConstraints] as the final step in your implementation.

## See Also

### Observing data in views

- [Updating views automatically with observation tracking](appkit/updating-views-automatically-with-observation-tracking.md)
- [layout()](appkit/nsview/layout().md)
- [updateLayer()](appkit/nsview/updatelayer().md)
- [draw(_:)](appkit/nsview/draw(_:).md)
