The NSOrthography class describes the linguistic content of a piece of text, typically used for the purposes of spelling and grammar checking.


An NSOrthography instance describes:

  • Which scripts the text contains.

  • A dominant language and possibly other languages for each of these scripts.

  • A dominant script and language for the text as a whole.

Scripts are uniformly described by standard four-letter tags (Latn, Grek, Cyrl, etc.) with the supertags Jpan and Kore typically used for Japanese and Korean text, Hans and Hant for Chinese text; the tag Zyyy is used if a specific script cannot be identified. See Internationalization and Localization Guide for more information on internationalization.

Languages are uniformly described by BCP-47 tags , preferably in canonical form; the tag und is used if a specific language cannot be determined.

Subclassing Notes

Methods to Override

The dominantScript and languageMap properties are the primitive values that a subclass must implement. The properties are set using the init(dominantScript:languageMap:) or orthographyWithDominantScript:languageMap:.


Creating Instances of NSOrthography

init(dominantScript: String, languageMap: [String : [String]])

Creates and returns an orthography instance with the specified dominant script and language map.

Defining the Language Map

var dominantScript: String

The dominant script for the text.

var languageMap: [String : [String]]

A dictionary that map script tags to arrays of language tags.

Managing Languages and Scripts

func languages(forScript: String)

Returns the list of languages for the specified script.

func dominantLanguage(forScript: String)

Returns the dominant language for the specified script.

var allLanguages: [String]

Returns an array containing all the languages appearing in the values of the language map.

var allScripts: [String]

Returns an array containing all the scripts appearing as keys in the language map.

var dominantLanguage: String

Returns the first language in the list of languages for the dominant script.


Inherits From