Generic Subscript

subscript(dynamicMember:)

Returns a scoped attribute container that a key path indicates. あるスコープ付き属性コンテナを返します、それはあるキーパスが指し示すものです。

Declaration 宣言

subscript<S>(dynamicMember keyPath: KeyPath<AttributeScopes, S.Type>) -> ScopedAttributeContainer<S> where S : AttributeScope { get set }

Discussion 議論

Use this subscript when you need to work with an explicit attribute scope. For example, the SwiftUI 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 myAttributedSubstring.uiKit.foregroundColor to disambiguate and explicitly use the UIKit attribute. この添え字(subscript)を、あなたがある明示的な属性スコープを扱う必要がある時は使用してください。、例えば、SwiftUI foregroundColor属性は、AppKitとUIKitスコープにおける属性を同じ名前でオーバーライドします。あなたがSwiftUIとUIKit スコープの両方で作業するならば、あなたは構文myAttributedSubstring.uiKit.foregroundColorを使って曖昧さを除きそして明示的にUIKit属性を使うことができます。

The attribute container that this method returns contains only attributes that exist, and are present and identical for the entire attributed string. To find portions of the string with consistent attributes, use the runs property. このメソッドが返す属性コンテナは、存在する属性のみを含みます、そしてその属性付き文字列の全体のために存在してそして同一的です。文字列の一部分を持続的属性で見つけるには、runsプロパティを使ってください。

Getting or setting stringwide attributes with this subscript has O(n) behavior in the worst case, where n is the number of runs. 文字列全体にわたる属性をこの添え字で取得および設定することは、O(n)挙動を最悪の場合には持ちます、そこでnはrunsの数です。

Relationships 関係

From Protocol 由来プロトコル

See Also 参照

Accessing Whole-Substring Attributes 下位文字列属性全体にアクセスする