AttributeScope
A type that organizes attributes into a grouping, and supports dynamic member lookup and serialization of attribute keys.
Declaration
protocol AttributeScope : DecodingConfigurationProviding, EncodingConfigurationProviding, SendableMetatypeOverview
Attribute owners — typically frameworks — define attributes with AttributedStringKey types. To allow access to attributes with dynamic member lookup, owners create one or more structures that conform to AttributeScope. The scopes provide short names for their attributes that map to the AttributedStringKey type. The following example shows how to do this:
struct TextStyleAttributes : AttributeScope {
let foregroundColor : ForegroundColorAttribute // ForegroundColorAttribute.Value == Color
let backgroundColor : BackgroundColorAttribute // BackgroundColorAttribute.Value == Color
let underlineStyle : UnderlineStyleAttribute // UnderlineStyleAttribute.Value == UnderlineStyle
// etc.
}This allows callers to use a syntax like myAttributedString.foregroundColor = .red.