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

# constraint(lessThanOrEqualToConstant:)

Returns a constraint that defines the maximum size for the anchor’s size attribute.

```
func constraint(lessThanOrEqualToConstant c: CGFloat) -> NSLayoutConstraint
```

## Parameters

`c`

A constant representing the maximum size of the attribute associated with this dimension anchor.

## Return Value

An [`NSLayoutConstraint`](/documentation/AppKit/NSLayoutConstraint) object that defines a maximum size for the attribute associated with this dimension anchor.

## Discussion

This method defines the relationship `first attribute <= c`. Where `first attribute` is the layout attribute represented by the anchor receiving this method call.

The constraints produced by the following two examples are identical.

```swift
// Creating a constraint using NSLayoutConstraint
NSLayoutConstraint(item: button,
                   attribute: .Width,
                   relatedBy: .LessThanOrEqual,
                   toItem: nil,
                   attribute: .NotAnAttribute,
                   multiplier: 1.0,
                   constant: 40.0).isActive = true
 
// Creating the same constraint using constraintLessThanOrEqualToConstant:
button.widthAnchor.constraintLessThanOrEqualToConstant(40.0).isActive = true
```

---

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)