<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/AttributedString/WritingDirection",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation16AttributedStringV16WritingDirectionO"
  },
  "title" : "AttributedString.WritingDirection"
}
-->

# AttributedString.WritingDirection

The writing direction of a piece of text.

```
@frozen enum WritingDirection
```

## Overview

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 [`AttributedString.WritingDirection.leftToRight`](/documentation/Foundation/AttributedString/WritingDirection/leftToRight)
writing direction puts the directional run that is placed first in the
storage leftmost, and places subsequent directional runs towards the
right. The [`AttributedString.WritingDirection.rightToLeft`](/documentation/Foundation/AttributedString/WritingDirection/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`
[`characterDirection`](/documentation/Foundation/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
[`characterDirection`](/documentation/Foundation/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`
[`characterDirection`](/documentation/Foundation/Locale/Language-swift.struct/characterDirection)) words, should use
a [`AttributedString.WritingDirection.leftToRight`](/documentation/Foundation/AttributedString/WritingDirection/leftToRight) writing direction. An Arabic sentence that contains
some English words, should use a [`AttributedString.WritingDirection.rightToLeft`](/documentation/Foundation/AttributedString/WritingDirection/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
[`lineLayoutDirection`](/documentation/Foundation/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 [`AttributedString.WritingDirection.leftToRight`](/documentation/Foundation/AttributedString/WritingDirection/leftToRight)
is interpreted as top-to-bottom and a writing direction of
[`AttributedString.WritingDirection.rightToLeft`](/documentation/Foundation/AttributedString/WritingDirection/rightToLeft) is interpreted as bottom-to-top.

## Topics

### Enumeration Cases

[`case leftToRight`](/documentation/Foundation/AttributedString/WritingDirection/leftToRight)

A left-to-right writing direction in horizontal script.

[`case rightToLeft`](/documentation/Foundation/AttributedString/WritingDirection/rightToLeft)

A right-to-left writing direction in horizontal script.

## Relationships

### Conforms To

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

[`Copyable`](/documentation/Swift/Copyable)

[`Decodable`](/documentation/Swift/Decodable)

[`CaseIterable`](/documentation/Swift/CaseIterable)

[`BitwiseCopyable`](/documentation/Swift/BitwiseCopyable)

[`Encodable`](/documentation/Swift/Encodable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)