<!--
{
  "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/init(for:values:default:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI24AttributedTextFormattingO15ValueConstraintV3for6values7defaultAEy_xq_Gq_m_Shy0F0Qy_SgGALtcfc::OverloadGroup"
  },
  "title" : "init(for:values:default:)"
}
-->

# init(for:values:default:)

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

```
init(for attribute: AttributeKey.Type, values allowedValues: Set<AttributeKey.Value?>, default defaultValue: AttributeKey.Value?)
```

## Parameters

`attribute`

An attribute to constrain to a set of
allowed values.

`allowedValues`

A set of values that are permitted.

`defaultValue`

A single permitted value that is used to
replace any values that are not in the set of `allowedValues`.

---

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)