One Logo Pool Ball
Foundation · IOS API REFERENCE

AttributedString.WritingDirection

enum · iOS 26.0+ · SDK 27.1

@frozen enum WritingDirection

The writing direction of a piece of text. Writing direction defines the base direction in which bidirectional text lays out its directional runs. A directional run is a contiguous sequence of characters that all have the same effective directionality, which can be determined using the Unicode BiDi algorithm. The ``leftToRight`` writing direction puts the directional run that is placed first in the storage leftmost, and places subsequent directional runs towards the right. The ``rightToLeft`` writing direction puts the directional run that is placed first in the storage rightmost, and places subsequent directional runs towards the left. Note that writing direction is a property separate from a text's alignment, its line layout direction, or its character direction. However, it is often used to determine the default alignment of a paragraph. E.g. English (a language with ``Locale/LanguageDirection-swift.enum/leftToRight`` ``Locale/Language-swift.struct/characterDirection``) is usually aligned to the left, but may be centered or aligned to the right for special effect, or to be visually more appealing in a user interface. For bidirectional text to be perceived as laid out correctly, make sure that the writing direction is set to the value equivalent to the ``Locale/Language-swift.struct/characterDirection`` of the primary language in the text. E.g. an English sentence that contains some Arabic (a language with ``Locale/LanguageDirection-swift.enum/rightToLeft`` ``Locale/Language-swift.struct/characterDirection``) words, should use a ``leftToRight`` writing direction. An Arabic sentence that contains some English words, should use a ``rightToLeft`` writing direction. Writing direction is always orthogonoal to the line layout direction chosen to display a certain text. The line layout direction is the direction in which a sequence of lines is placed in. E.g. English text is usually displayed with a line layout direction of ``Locale/LanguageDirection-swift.enum/topToBottom``. While languages do have an associated line language direction (see ``Locale/Language-swift.struct/lineLayoutDirection``), not all displays of text follow the line layout direction of the text's primary language. Horizontal script is script with a line layout direction of either ``Locale/LanguageDirection-swift.enum/topToBottom`` or ``Locale/LanguageDirection-swift.enum/bottomToTop``. Vertical script has a ``Locale/LanguageDirection-swift.enum/leftToRight`` or ``Locale/LanguageDirection-swift.enum/rightToLeft`` line layout direction. In vertical scripts, a writing direction of ``leftToRight`` is interpreted as top-to-bottom and a writing direction of ``rightToLeft`` is interpreted as bottom-to-top.

Members (1)

get · iOS 26.0+

allCases

TypeScript
get allCases(): Array<AttributedString_WritingDirection>
Swift declaration
nonisolated static var allCases: [AttributedString.WritingDirection] { get }

A collection of all values of this type.

Skipped declarations

No declarations were skipped in this snapshot.

All Foundation types →