One Logo Pool Ball
Foundation · IOS API REFERENCE

AttributedStringKey

protocol · iOS 15.0+ · SDK 27.1

protocol AttributedStringKey : SendableMetatype

A type that defines an attribute's name and type. You don't instantiate types that conform to this protocol. Rather, dynamic member lookup uses this type as the basis for looking up key paths on ``AttributedString`` subtypes when using an ``AttributeScope`` type parameter. When it also conforms to ``CodableAttributedStringKey``, (or ``DecodableAttributedStringKey``/``EncodableAttributedStringKey`` if the type isn't fully codable), the ``AttributedStringKey`` describes which attributes of an ``AttributedString`` support encoding or decoding. Attribute owners — typically frameworks — declare a key like the following: ```swift enum OutlineColorAttribute : AttributedStringKey { typealias Value = Color static let name = "OutlineColor" } ``` Callers can use these types to get attribute values from attributed strings, but typically you want to reference them by name. Attribute owners enable this by creating one or more structures that conform to ``AttributeScope``, in which they provide short names for their attributes that map to the ``AttributedStringKey`` type. The following example shows how to do this: ```swift struct MyTextStyleAttributes : AttributeScope { let outlineColor : OutlineColorAttribute // OutlineColorAttribute.Value == Color let shadowColor : ShadowColorAttribute // ShadowColorAttribute.Value == Color // etc. } ``` After you extend ``AttributeScope`` like this, extend ``AttributeDynamicLookup`` to allow callers to use dynamic member lookup syntax, like `myAttributedString.outlineColor = .red`.

Members (1)

get · iOS 15.0+

description

Swift declaration
var description: String { get }

Skipped declarations

3 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

AttributedStringKey.runBoundaries

Static protocol requirements cannot be called through an instance.

AttributedStringKey.inheritedByAddedText

Static protocol requirements cannot be called through an instance.

AttributedStringKey.invalidationConditions

Static protocol requirements cannot be called through an instance.

All Foundation types →