<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.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/NSTextCheckingResult",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextCheckingResult"
  },
  "title" : "NSTextCheckingResult"
}
-->

# NSTextCheckingResult

An occurrence of textual content found during the analysis of a block of text, such as when matching a regular expression.

```
class NSTextCheckingResult
```

## Overview

On both iOS and macOS, instances of [`NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult) are returned by the [`NSRegularExpression`](/documentation/Foundation/NSRegularExpression) class and the [`NSDataDetector`](/documentation/Foundation/NSDataDetector) class to indicate the discovery of content. In those cases, what is found may be a match for a regular expression or a date, address, phone number, and so on. In macOS, instances of `NSTextCheckingResult` are returned by the <doc://com.apple.documentation/documentation/AppKit/NSSpellChecker> object to describe the results of spelling, grammar, or text-substitution actions.

## Topics

### Text Checking Type Range and Type

[`var range: NSRange`](/documentation/Foundation/NSTextCheckingResult/range)

Returns the range of the result that the receiver represents.

[`var resultType: NSTextCheckingResult.CheckingType`](/documentation/Foundation/NSTextCheckingResult/resultType)

Returns the text checking result type that the receiver represents.

[`var numberOfRanges: Int`](/documentation/Foundation/NSTextCheckingResult/numberOfRanges)

Returns the number of ranges.

[`func range(at: Int) -> NSRange`](/documentation/Foundation/NSTextCheckingResult/range(at:))

Returns the result type that the range represents.

### Text Checking Results for Text Replacement

[`class func replacementCheckingResult(range: NSRange, replacementString: String) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/replacementCheckingResult(range:replacementString:))

Creates and returns a text checking result with the specified replacement string.

[`var replacementString: String?`](/documentation/Foundation/NSTextCheckingResult/replacementString)

A replacement string from one of a number of replacement checking results.

### Text Checking Results for Regular Expressions

[`class func regularExpressionCheckingResult(ranges: NSRangePointer, count: Int, regularExpression: NSRegularExpression) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/regularExpressionCheckingResult(ranges:count:regularExpression:))

Creates and returns a type checking result with the specified regular expression data.

[`var regularExpression: NSRegularExpression?`](/documentation/Foundation/NSTextCheckingResult/regularExpression)

The regular expression of a type checking result.

### Text Checking Result Components

[`var components: [NSTextCheckingKey : String]?`](/documentation/Foundation/NSTextCheckingResult/components)

A dictionary containing the components of a type checking result.

### Text Checking Results for URLs

[`class func linkCheckingResult(range: NSRange, url: URL) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/linkCheckingResult(range:url:))

Creates and returns a text checking result with the specified URL.

[`var url: URL?`](/documentation/Foundation/NSTextCheckingResult/url)

The URL of a type checking result.

### Text Checking Results for Addresses

[`class func addressCheckingResult(range: NSRange, components: [NSTextCheckingKey : String]) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/addressCheckingResult(range:components:))

Creates and returns a text checking result with the specified address components.

[`var addressComponents: [NSTextCheckingKey : String]?`](/documentation/Foundation/NSTextCheckingResult/addressComponents)

The address dictionary of a type checking result.

### Text Checking Results for Transit Information

[`class func transitInformationCheckingResult(range: NSRange, components: [NSTextCheckingKey : String]) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/transitInformationCheckingResult(range:components:))

Creates and returns a text checking result with the specified transit information.

### Text Checking Results for Phone Numbers

[`class func phoneNumberCheckingResult(range: NSRange, phoneNumber: String) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/phoneNumberCheckingResult(range:phoneNumber:))

Creates and returns a text checking result with the specified phone number.

[`var phoneNumber: String?`](/documentation/Foundation/NSTextCheckingResult/phoneNumber)

The phone number of a type checking result.

### Text Checking Results for Dates and Times

[`class func dateCheckingResult(range: NSRange, date: Date) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/dateCheckingResult(range:date:))

Creates and returns a text checking result with the specified date.

[`class func dateCheckingResult(range: NSRange, date: Date, timeZone: TimeZone, duration: TimeInterval) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/dateCheckingResult(range:date:timeZone:duration:))

Creates and returns a text checking result with the specified date, time zone, and duration.

[`var date: Date?`](/documentation/Foundation/NSTextCheckingResult/date)

The date component of a type checking result.

[`var duration: TimeInterval`](/documentation/Foundation/NSTextCheckingResult/duration)

The duration component of a type checking result.

[`var timeZone: TimeZone?`](/documentation/Foundation/NSTextCheckingResult/timeZone)

The time zone component of a type checking result.

### Text Checking Results for Typography

[`class func dashCheckingResult(range: NSRange, replacementString: String) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/dashCheckingResult(range:replacementString:))

Creates and returns a text checking result with the specified dash corrected replacement string.

[`class func quoteCheckingResult(range: NSRange, replacementString: String) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/quoteCheckingResult(range:replacementString:))

Creates and returns a text checking result with the specified quote-balanced replacement string.

### Text Checking Results for Spelling

[`class func spellCheckingResult(range: NSRange) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/spellCheckingResult(range:))

Creates and returns a text checking result with the range of a misspelled word.

[`class func correctionCheckingResult(range: NSRange, replacementString: String) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/correctionCheckingResult(range:replacementString:))

Creates and returns a text checking result after detecting a possible correction.

### Text Checking Results for Orthography

[`class func orthographyCheckingResult(range: NSRange, orthography: NSOrthography) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/orthographyCheckingResult(range:orthography:))

Creates and returns a text checking result with the specified orthography.

[`var orthography: NSOrthography?`](/documentation/Foundation/NSTextCheckingResult/orthography)

The detected orthography of a type checking result.

### Text Checking Results for Grammar

[`class func grammarCheckingResult(range: NSRange, details: [[String : Any]]) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/grammarCheckingResult(range:details:))

Creates and returns a text checking result with the specified array of grammatical errors.

[`var grammarDetails: [[String : Any]]?`](/documentation/Foundation/NSTextCheckingResult/grammarDetails)

The details of a located grammatical type checking result.

### Adjusting the Ranges of a Text Checking Result

[`func adjustingRanges(offset: Int) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/adjustingRanges(offset:))

Returns a new text checking result after adjusting the ranges as specified by the offset.

### Constants

[Keys for Transit Components](/documentation/Foundation/keys-for-transit-components)

The following constants identify the possible keys returned in the components dictionary.

[Keys for Address Components](/documentation/Foundation/keys-for-address-components)

The following constants identify the possible keys returned in the [`addressComponents`](/documentation/Foundation/NSTextCheckingResult/addressComponents) dictionary.

[`struct CheckingType`](/documentation/Foundation/NSTextCheckingResult/CheckingType)

These constants specify the type of checking the methods should do. They are returned by [`resultType`](/documentation/Foundation/NSTextCheckingResult/resultType).

[`typealias NSTextCheckingTypes`](/documentation/Foundation/NSTextCheckingTypes)

Defines the types of checking that are available. These values can be combined using the C-bitwise OR operator. The system supports its own internal types, and the user can extend those types by subclassing `NSTextCheckingResult` and adding their own custom types.

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

[Anonymous](/documentation/Foundation/1476845-anonymous)

### Initializers

[`init?(coder: NSCoder)`](/documentation/Foundation/NSTextCheckingResult/init(coder:))

### Instance Properties

[`var alternativeStrings: [String]?`](/documentation/Foundation/NSTextCheckingResult/alternativeStrings)

### Instance Methods

[`func range(withName: String) -> NSRange`](/documentation/Foundation/NSTextCheckingResult/range(withName:))

### Type Methods

[`class func correctionCheckingResult(range: NSRange, replacementString: String, alternativeStrings: [String]) -> NSTextCheckingResult`](/documentation/Foundation/NSTextCheckingResult/correctionCheckingResult(range:replacementString:alternativeStrings:))

## Relationships

### Conforms To

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

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

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

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

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

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

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

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)