---
title: AttributedTextFormatting.ValueConstraint
framework: swiftui
role: symbol
role_heading: Structure
path: swiftui/attributedtextformatting/valueconstraint
---

# AttributedTextFormatting.ValueConstraint

A text formatting definition that constrains the value of a single attribute to the members of a set.

## Declaration

```swift
struct ValueConstraint<Scope, AttributeKey> where Scope : AttributeScope, AttributeKey : AttributedStringKey, AttributeKey.Value : Sendable
```

## Overview

Overview struct MyTextFormattingDefinition: AttributedTextFormattingDefinition {     var body: some AttributedTextFormattingDefinition<         AttributeScopes.SwiftUIAttributes     > {         // Allow no underline or the `.single` underline style. If         // a text has any other underline style, it is corrected         // to the default value `.single`         ValueConstraint(             for: \.underlineStyle,             values: [nil, .single],             default: .single)     } }

## Topics

### Initializers

- [init(for:values:default:)](swiftui/attributedtextformatting/valueconstraint/init(for:values:default:).md)

## Relationships

### Conforms To

- [AttributedTextFormattingDefinition](swiftui/attributedtextformattingdefinition.md)
- [AttributedTextValueConstraint](swiftui/attributedtextvalueconstraint.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
