<!--
{
  "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/AttributedTextFormatting/ValueConstraint",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI24AttributedTextFormattingO15ValueConstraintV"
  },
  "title" : "AttributedTextFormatting.ValueConstraint"
}
-->

# AttributedTextFormatting.ValueConstraint

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

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

## 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:)`](/documentation/SwiftUI/AttributedTextFormatting/ValueConstraint/init(for:values:default:))

Create a definition that constrains an attribute’s value to a
defined set of allowed values.

## Relationships

### Conforms To

[`AttributedTextValueConstraint`](/documentation/SwiftUI/AttributedTextValueConstraint)

[`Hashable`](/documentation/Swift/Hashable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Equatable`](/documentation/Swift/Equatable)

[`Sendable`](/documentation/Swift/Sendable)

[`AttributedTextFormattingDefinition`](/documentation/SwiftUI/AttributedTextFormattingDefinition)

---

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)