Instance Method インスタンスメソッド

attributedString(for:withDefaultAttributes:)

The default implementation returns nil to indicate that the formatter object does not provide an attributed string. 省略時の実装は、nilを返して、フォーマッタオブジェクトが属性付き文字列を提供しないことを指し示します。

Declaration 宣言

func attributedString(for obj: Any, 
withDefaultAttributes attrs: [NSAttributedString.Key : Any]? = nil) -> NSAttributedString?

Parameters パラメータ

anObject

The object for which a textual representation is returned. このオブジェクトに対するテキスト表現が返されます。

attributes

The default attributes to use for the returned attributed string. 返される属性付き文字列のために使われる初期状態の属性。

Return Value 戻り値

An attributed string that represents anObject. anObjectを表す属性付き文字列。

Discussion 議論

When implementing a subclass, return an NSAttributedString object if the string for display should have some attributes. For instance, you might want negative values in a financial application to appear in red text. Invoke your implementation of string(for:) to get the non-attributed string, then create an NSAttributedString object with it (see init(string:)). Use the attributes default dictionary to reset the attributes of the string when a change in value warrants it (for example, a negative value becomes positive) For information on creating attributed strings, see Attributed String Programming Guide. サブクラスを実装する場合、表示用文字列がいくつかの属性を持つべきならば、NSAttributedStringオブジェクトを返してください。例えば、あなたは負の値が財務アプリケーションにおいて赤いテキストで現れることを望むかもしれません。string(for:)のあなたの実装を発動して属性なし文字列を得てください、それからそれを使ってNSAttributedStringオブジェクトを作成してください(init(string:)を見てください)。attributes初期状態辞書を使って、それを要する変更が値にある(例えば、負の値が正になる)場合は、文字列の属性を規定値に戻してください。属性付き文字列の作成に関する情報として、Attributed String Programming Guideを見てください。

See Also 参照

Getting Textual Representations of Object Values オブジェクト値のテキスト表現を得る