<!--
{
  "availability" : [
    "macOS: 10.11.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSLayoutDimension/constraint(equalTo:multiplier:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSLayoutDimension(im)constraintEqualToAnchor:multiplier:"
  },
  "title" : "constraint(equalTo:multiplier:)"
}
-->

# constraint(equalTo:multiplier:)

Returns a constraint that defines the anchor’s size attribute as equal to the specified anchor multiplied by the constant.

```
func constraint(equalTo anchor: NSLayoutDimension, multiplier m: CGFloat) -> NSLayoutConstraint
```

## Parameters

`anchor`

A dimension anchor from an [`NSView`](/documentation/AppKit/NSView) or [`NSLayoutGuide`](/documentation/AppKit/NSLayoutGuide) object.

`m`

The multiplier constant for the constraint.

## Return Value

An [`NSLayoutConstraint`](/documentation/AppKit/NSLayoutConstraint) object that defines the attribute represented by this layout anchor as equal to the attribute represented by the `anchor` parameter multiplied by the `m` constant.

## Discussion

This method defines the relationship `first attribute = m * 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.

```swift
// Creating a constraint using NSLayoutConstraint
NSLayoutConstraint(item: saveButton,
                   attribute: .Width,
                   relatedBy: .Equal,
                   toItem: cancelButton,
                   attribute: .Width,
                   multiplier: 2.0,
                   constant: 0.0).isActive = true
 
// Creating the same constraint using constraintEqualToAnchor:multiplier:
saveButton.widthAnchor.constraintEqualToAnchor(cancelButton.widthAnchor, multiplier: 2.0).isActive = true
```

## See Also

[`NSLayoutConstraint`](/documentation/AppKit/NSLayoutConstraint)

The relationship between two user interface objects that must be satisfied by the constraint-based layout system.

[`NSLayoutAnchor`](/documentation/AppKit/NSLayoutAnchor)

A factory class for creating layout constraint objects using a fluent API.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)