InflectionRule
A rule that affects how an attributed string performs automatic grammatical agreement.
Declaration
enum InflectionRuleOverview
Most apps can rely on loading localized strings to perform automatic grammar agreement. Typically, strings in your app’s strings files use the Markdown extension syntax to indicate portions of the string that may require inflection to agree grammatically. This transformation occurs when you load the attributed string with methods like init(localized:options:table:bundle:locale:comment:).
However, if the system lacks information about the words in the string, you may need to apply an inflection rule programmatically. For example, a social networking app may have gender information about other users that you want to apply at runtime. When performing manual inflection at runtime, you use an inflection rule to indicate to the system what portions of a string should be automatically edited, and what to match. Apply the inflect attribute to set an InflectionRule on an AttributedString, then call inflected() to perform the grammar agreement and produce an edited string.
var string = AttributedString(localized: "They liked your post.")
// The user who liked the post uses feminine pronouns.
var morphology = Morphology()
morphology.grammaticalGender = .feminine
string.inflect = InflectionRule(morphology: morphology)
let result = string.inflected()
// result == "She liked your post."