<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/AttributedTextFormattingDefinition/constrain(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI34AttributedTextFormattingDefinitionPAAE9constrainyy10Foundation18AttributeContainerVzF::OverloadGroup"
  },
  "title" : "constrain(_:)"
}
-->

# constrain(_:)

Applies all value constraints to a given attribute container.

```
func constrain(_ container: inout AttributeContainer)
```

## Discussion

Modifies the given `container` by applying all
[`AttributedTextValueConstraint`](/documentation/SwiftUI/AttributedTextValueConstraint)s that are part of this definition to
the container.

Use this function to test your [`AttributedTextFormattingDefinition`](/documentation/SwiftUI/AttributedTextFormattingDefinition),
or to ensure your constraints are applied before passing content to API
that cannot itself apply the definition.

---

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)