<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: 13.1.0 -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CALayer/addConstraint(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Animation",
      "QuartzCore"
    ],
    "preciseIdentifier" : "c:objc(cs)CALayer(im)addConstraint:"
  },
  "title" : "addConstraint(_:)"
}
-->

# addConstraint(_:)

Adds the specified constraint to the layer.

```
func addConstraint(_ c: CAConstraint)
```

## Parameters

`c`

The constraint object to add to the receiver’s array of constraint objects.

## Discussion

In macOS, you typically add constraints to a layer to manage the size and position of that layer’s sublayers. Before constraints can be applied, you must also assign a [`CAConstraintLayoutManager`](/documentation/QuartzCore/CAConstraintLayoutManager) object to the [`layoutManager`](/documentation/QuartzCore/CALayer/layoutManager) property of the layer. For more information about managing layer-based constraints, see [Core Animation Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004514).

iOS apps do not support layer-based constraints.

---

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)