Skip to content

Instance Subscript

subscript(dynamicMember:)

iOS 15.0+ iPadOS 15.0+ Mac Catalyst 15.0+ macOS 12.0+ tvOS 15.0+ watchOS 8.0+
Returns a scoped attribute container that a key path indicates.
subscript<S>(dynamicMember keyPath: KeyPath<AttributeScopes, S.Type>) -> ScopedAttributeContainer<S> where S : AttributeScope { get set }

Overview

Use this subscript when you need to work with an explicit attribute scope. For example, the SwiftUI AttributeScopes/SwiftUIAttributes/foregroundColor attribute overrides the attribute in the AppKit and UIKit scopes with the same name. If you work with both the SwiftUI and UIKit scopes, you can use the syntax myAttributedString.uiKit.foregroundColor to disambiguate and explicitly use the UIKit attribute.