---
title: "attributedTextFormattingDefinition(_:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/attributedtextformattingdefinition(_:)"
---

# attributedTextFormattingDefinition(_:)

Apply a text formatting definition to nested views.

## Declaration

```swift
nonisolated func attributedTextFormattingDefinition<D>(_ definition: D) -> some View where D : AttributedTextFormattingDefinition

```

## Discussion

Discussion Applying a text formatting definition to a Text or TextEditor created using the init(_:) or init(text:selection:) initializer, respectively, makes sure that any content observable to the user adheres to the constraints of the formatting definition. You can compose your own definition from an attribute scope and a series of AttributedTextValueConstraints: // MyTextFormattingDefinition.swift

struct MyTextFormattingDefinition: AttributedTextFormattingDefinition {     var body: some AttributedTextFormattingDefinition<         AttributeScopes.SwiftUIAttributes     > {         ValueConstraint(             for: \.underlineStyle,             values: [nil, .single],             default: .single)         MyAttributedTextValueConstraint()     } }

// MyEditorView.swift

TextEditor(text: $text)     .attributedTextFormattingDefinition(MyTextFormattingDefinition()) note: A Binding to the text of a view with an AttributedTextFormattingDefinition may still contain values that do not adhere to text formatting definition. E.g., a TextEditor may choose to not apply constraints in the text formatting definition to parts of a bound attributed string that are not visible on screen. To manually enforce constraints, e.g. before serializing text contents, use the constrain(_:) method.

## See Also

### Text style

- [bold(_:)](swiftui/view/bold(_:).md)
- [fontDesign(_:)](swiftui/view/fontdesign(_:).md)
- [fontWeight(_:)](swiftui/view/fontweight(_:).md)
- [fontWidth(_:)](swiftui/view/fontwidth(_:).md)
- [italic(_:)](swiftui/view/italic(_:).md)
- [monospaced(_:)](swiftui/view/monospaced(_:).md)
- [monospacedDigit()](swiftui/view/monospaceddigit().md)
- [strikethrough(_:pattern:color:)](swiftui/view/strikethrough(_:pattern:color:).md)
- [textCase(_:)](swiftui/view/textcase(_:).md)
- [textScale(_:isEnabled:)](swiftui/view/textscale(_:isenabled:).md)
- [textRenderer(_:)](swiftui/view/textrenderer(_:).md)
- [underline(_:pattern:color:)](swiftui/view/underline(_:pattern:color:).md)
