<!--
{
  "availability" : [
    "iOS: 6.0.0 -",
    "iPadOS: 6.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAttributedString/Key/writingDirection",
  "metadataVersion" : "0.1.0",
  "role" : "Type Property",
  "symbol" : {
    "kind" : "Type Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@NSWritingDirectionAttributeName"
  },
  "title" : "writingDirection"
}
-->

# writingDirection

The writing direction of the text.

```
static let writingDirection: NSAttributedString.Key
```

## Discussion

The value of this attribute is an [`NSArray`](/documentation/Foundation/NSArray) object containing [`NSNumber`](/documentation/Foundation/NSNumber) objects representing the nested levels of writing direction overrides, in order from outermost to innermost.

This attribute provides a means to override the default bidirectional text algorithm, equivalent to using the Unicode bidi control characters `LRE`, `RLE`, `LRO`, or `RLO` paired with `PDF`, but as a higher-level attribute. (See [Unicode Standard Annex #9](http://unicode.org/reports/tr9/) for information about the Unicode bidi formatting codes.) The `NSWritingDirectionAttributeName` constant is a character-level attribute that provides a higher-level alternative to the inclusion of explicit bidirectional control characters in text. It is the `NSAttributedString` equivalent of the HTML markup using `bdo` element with the `dir` attribute.

The values of the `NSNumber` objects should be `0`, `1`, `2`, or `3`, for `LRE`, `RLE`, `LRO`, or `RLO` respectively, and combinations of <doc://com.apple.documentation/documentation/AppKit/NSWritingDirection/leftToRight> and <doc://com.apple.documentation/documentation/AppKit/NSWritingDirection/rightToLeft> with <doc://com.apple.documentation/documentation/AppKit/NSTextWritingDirectionEmbedding> or `NSTextWritingDirectionOverride`, as shown in the following table.

|Array NSNumber Values|Unicode Control Characters|Writing Direction Constants                                        |
|---------------------|--------------------------|-------------------------------------------------------------------|
|`0`                  |`LRE`                     |`NSWritingDirectionLeftToRight` | `NSTextWritingDirectionEmbedding`|
|`1`                  |`RLE`                     |`NSWritingDirectionRightToLeft` | `NSTextWritingDirectionEmbedding`|
|`2`                  |`LRO`                     |`NSWritingDirectionLeftToRight` | `NSTextWritingDirectionOverride` |
|`3`                  |`RLO`                     |`NSWritingDirectionRightToLeft` | `NSTextWritingDirectionOverride` |

---

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)