---
title: "constraint(equalTo:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nslayoutanchor/constraint(equalto:)"
---

# constraint(equalTo:)

Returns a constraint that defines one item’s attribute as equal to another.

## Declaration

```swift
func constraint(equalTo anchor: NSLayoutAnchor<AnchorType>) -> NSLayoutConstraint
```

## Parameters

- `anchor`: A layout anchor from an doc://com.apple.appkit/documentation/AppKit/NSView or doc://com.apple.appkit/documentation/AppKit/NSLayoutGuide object. You must use a subclass of doc://com.apple.appkit/documentation/AppKit/NSLayoutAnchor that matches the current anchor. For example, if you call this method on an doc://com.apple.appkit/documentation/AppKit/NSLayoutXAxisAnchor object, this parameter must be another doc://com.apple.appkit/documentation/AppKit/NSLayoutXAxisAnchor.

## Return Value

Return Value An NSLayoutConstraint object that defines an equal relationship between the attributes represented by the two layout anchors.

## Discussion

Discussion This method defines the relationship first attribute = second attribute. Where first attribute is the layout attribute represented by the anchor receiving this method call, and second attribute is the layout attribute represented by the anchor parameter. The constraints produced by the following two examples are identical.

## See Also

### Related Documentation

- [NSLayoutConstraint](appkit/nslayoutconstraint.md)
- [NSLayoutAnchor](appkit/nslayoutanchor.md)

### Building constraints

- [constraint(equalTo:constant:)](appkit/nslayoutanchor/constraint(equalto:constant:).md)
- [constraint(greaterThanOrEqualTo:)](appkit/nslayoutanchor/constraint(greaterthanorequalto:).md)
- [constraint(greaterThanOrEqualTo:constant:)](appkit/nslayoutanchor/constraint(greaterthanorequalto:constant:).md)
- [constraint(lessThanOrEqualTo:)](appkit/nslayoutanchor/constraint(lessthanorequalto:).md)
- [constraint(lessThanOrEqualTo:constant:)](appkit/nslayoutanchor/constraint(lessthanorequalto:constant:).md)
