---
title: "addConstraint(_:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsview/addconstraint(_:)"
---

# addConstraint(_:)

Adds a constraint on the layout of the receiving view or its subviews.

## Declaration

```swift
func addConstraint(_ constraint: NSLayoutConstraint)
```

## Parameters

- `constraint`: The constraint to be added to the view. The constraint may only reference the view itself or its subviews.

## Discussion

Discussion The constraint must involve only views that are within scope of the receiving view. Specifically, any views involved must be either the receiving view itself, or a subview of the receiving view. Constraints that are added to a view are said to be held by that view. The coordinate system used when evaluating the constraint is the coordinate system of the view that holds the constraint.

## See Also

### Managing the View’s Constraints

- [constraints](appkit/nsview/constraints.md)
- [addConstraints(_:)](appkit/nsview/addconstraints(_:).md)
- [removeConstraint(_:)](appkit/nsview/removeconstraint(_:).md)
- [removeConstraints(_:)](appkit/nsview/removeconstraints(_:).md)
