AttributedTextFormatting.ValueConstraint
A text formatting definition that constrains the value of a single attribute to the members of a set.
Declaration
struct ValueConstraint<Scope, AttributeKey> where Scope : AttributeScope, AttributeKey : AttributedStringKey, AttributeKey.Value : SendableOverview
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)
}
}