---
title: "constrain(_:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/attributedtextformattingdefinition/constrain(_:)-1ur9c"
---

# constrain(_:)

Applies all value constraints to a given attributed string.

## Declaration

```swift
func constrain(_ string: inout AttributedString)
```

## Discussion

Discussion Modifies the given string by applying all AttributedTextValueConstraints that are part of this definition to each run of the string. Use this function to test your AttributedTextFormattingDefinition, or to ensure your constraints are applied before passing content to API that cannot itself apply the definition.
