<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/InflectionRule",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation14InflectionRuleO"
  },
  "title" : "InflectionRule"
}
-->

# InflectionRule

A rule that affects how an attributed string performs automatic grammatical agreement.

```
enum InflectionRule
```

## Overview

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`](/documentation/Foundation/AttributeScopes/FoundationAttributes/inflect) attribute to set an [`InflectionRule`](/documentation/Foundation/InflectionRule) on an [`AttributedString`](/documentation/Foundation/AttributedString), then call [`inflected()`](/documentation/Foundation/AttributedString/inflected()) to perform the grammar agreement and produce an edited string.

```swift
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."
```

## Topics

### Creating an Inflection Rule from a Morphology

[`init(morphology: Morphology)`](/documentation/Foundation/InflectionRule/init(morphology:))

Creates an inflection rule with the given morphology.

[`struct Morphology`](/documentation/Foundation/Morphology)

A description of the grammatical properties of a string.

### Inflection Rule Behaviors

[`case automatic`](/documentation/Foundation/InflectionRule/automatic)

An inflection rule that performs automatic grammar agreement with default transformations.

[`case explicit(Morphology)`](/documentation/Foundation/InflectionRule/explicit(_:))

An inflection rule that uses a morphology instance to determine how to inflect attribued strings.

### Determining Availability

[`static func canInflect(language: String) -> Bool`](/documentation/Foundation/InflectionRule/canInflect(language:))

Returns a Boolean value that indicates whether the rule can inflect a given language.

[`static var canInflectPreferredLocalization: Bool`](/documentation/Foundation/InflectionRule/canInflectPreferredLocalization)

A Boolean value that indicates whether the rule can inflect the user’s current preferred localization.

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

---

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)