Protocol
AttributeScope
iOS 15.0+
iPadOS 15.0+
Mac Catalyst 15.0+
macOS 12.0+
tvOS 15.0+
watchOS 8.0+
A type that organizes attributes into a grouping, and supports dynamic member lookup and serialization of attribute keys.
protocol AttributeScope : DecodingConfigurationProviding, EncodingConfigurationProviding, SendableMetatype
Overview
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.
Topics
Type Properties
static var decodingConfiguration: AttributeScopeCodableConfigurationThe configuration for decoding the attribute scope.static var encodingConfiguration: AttributeScopeCodableConfigurationThe configuration for encoding the attribute scope.
Relationships
Inherits From
DecodingConfigurationProvidingEncodingConfigurationProvidingSwift.SendableMetatype