NSTextCheckingResult Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in OS X v10.6 and later. |
| Declared in | NSTextCheckingResult.h |
Overview
NSTextCheckingResult is a class used to describe items located by text checking. Each of these objects represents an occurrence of requested textual content that has been found during the analysis of a block of text.
On both iOS and OS X, instances of NSTextCheckingResult are returned by the NSRegularExpression class and the 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. On OS X, instances of NSTextCheckingResult are returned by the NSSpellChecker object to describe the results of spelling, grammar, or text-substitution actions.
Tasks
Text Checking Type Range and Type
-
rangeproperty -
resultTypeproperty -
numberOfRangesproperty -
– rangeAtIndex:
Text Checking Results for Text Replacement
Text Checking Results for Regular Expressions
Text Checking Result Components
-
componentsproperty
Text Checking Results for URLs
-
+ linkCheckingResultWithRange:URL: -
URLproperty
Text Checking Results for Addresses
Text Checking Results for Transit Information
Text Checking Results for Phone Numbers
Text Checking Results for Dates and Times
-
+ dateCheckingResultWithRange:date: -
+ dateCheckingResultWithRange:date:timeZone:duration: -
dateproperty -
durationproperty -
timeZoneproperty
Text Checking Results for Typography
Text Checking Results for Spelling
Text Checking Results for Orthography
Text Checking Results for Grammar
Adjusting the Ranges of a Text Checking Result
Properties
addressComponents
The address dictionary of a type checking result. (read-only)
Discussion
The dictionary keys are described in “Keys for Address Components.”
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.hcomponents
A dictionary containing the components of a type checking result. (read-only)
Discussion
Currently used by the transit checking result. The supported keys are located in “Keys for Transit Components.”
Availability
- Available in OS X v10.7 and later.
Declared In
NSTextCheckingResult.hdate
The date component of a type checking result. (read-only)
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.hduration
The duration component of a type checking result. (read-only)
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.hgrammarDetails
The details of a located grammatical type checking result. (read-only)
Discussion
This array of strings is suitable for presenting to the user.
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.hnumberOfRanges
Returns the number of ranges. (read-only)
Discussion
A result must have at least one range, but may optionally have more (for example, to represent regular expression capture groups).
Passing rangeAtIndex: the value 0 always returns the value of the the range property. Additional ranges, if any, will have indexes from 1 to numberOfRanges-1.
Availability
- Available in OS X v10.7 and later.
Declared In
NSTextCheckingResult.horthography
The detected orthography of a type checking result. (read-only)
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.hphoneNumber
The phone number of a type checking result. (read-only)
Availability
- Available in OS X v10.7 and later.
Declared In
NSTextCheckingResult.hrange
Returns the range of the result that the receiver represents. (read-only)
Discussion
This property will be present for all returned NSTextCheckingResult instances.
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSTextCheckingResult.hregularExpression
The regular expression of a type checking result. (read-only)
Availability
- Available in OS X v10.7 and later.
Declared In
NSTextCheckingResult.hreplacementString
A replacement string from one of a number of replacement checking results. (read-only)
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.hresultType
Returns the text checking result type that the receiver represents. (read-only)
Discussion
The possible result types for the built in checking capabilities are described in “NSTextCheckingType.”
This property will be present for all returned NSTextCheckingResult instances.
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.htimeZone
The time zone component of a type checking result. (read-only)
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.hURL
The URL of a type checking result. (read-only)
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSTextCheckingResult.hClass Methods
addressCheckingResultWithRange:components:
Creates and returns a text checking result with the specified address components.
Parameters
- range
The range of the detected result.
- components
A dictionary containing the address components. The dictionary keys are described in “Keys for Address Components.”
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeAddress.
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSTextCheckingResult.hcorrectionCheckingResultWithRange:replacementString:
Creates and returns a text checking result after detecting a possible correction.
Parameters
- range
The range of the detected result.
- replacementString
The suggested replacement string.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeSpelling.
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSTextCheckingResult.hdashCheckingResultWithRange:replacementString:
Creates and returns a text checking result with the specified dash corrected replacement string.
Parameters
- range
The range of the detected result.
- replacementString
The replacement string.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeDash.
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.hdateCheckingResultWithRange:date:
Creates and returns a text checking result with the specified date.
Parameters
- range
The range of the detected result.
- date
The detected date.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeDate.
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.hdateCheckingResultWithRange:date:timeZone:duration:
Creates and returns a text checking result with the specified date, time zone, and duration.
Parameters
- range
The range of the detected result.
- date
The detected date.
- timeZone
The detected time zone.
- duration
The detected duration.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeDate.
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.hgrammarCheckingResultWithRange:details:
Creates and returns a text checking result with the specified array of grammatical errors.
Parameters
- range
The range of the detected result.
- details
An array of details regarding the grammatical errors. This array of strings is suitable for presenting to the user.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeGrammar.
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSTextCheckingResult.hlinkCheckingResultWithRange:URL:
Creates and returns a text checking result with the specified URL.
Parameters
- range
The range of the detected result.
- url
The URL.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeLink.
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSTextCheckingResult.horthographyCheckingResultWithRange:orthography:
Creates and returns a text checking result with the specified orthography.
Parameters
- range
The range of the detected result.
- orthography
An orthography object that describes the script.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeOrthography.
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSTextCheckingResult.hphoneNumberCheckingResultWithRange:phoneNumber:
Creates and returns a text checking result with the specified phone number.
Parameters
- range
The range of the detected result.
- phoneNumber
The phone number.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypePhoneNumber.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSTextCheckingResult.hquoteCheckingResultWithRange:replacementString:
Creates and returns a text checking result with the specified quote-balanced replacement string.
Parameters
- range
The range of the detected result.
- replacementString
The replacement string.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeQuote.
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.hregularExpressionCheckingResultWithRanges:count:regularExpression:
Creates and returns a type checking result with the specified regular expression data.
Parameters
- ranges
A C array of ranges, which must have at least one element, and the first element represents the overall range.
- count
The number of items in the ranges array.
- regularExpression
The regular expression.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeRegularExpression.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSTextCheckingResult.hreplacementCheckingResultWithRange:replacementString:
Creates and returns a text checking result with the specified replacement string.
Parameters
- range
The range of the detected result.
- replacementString
The replacement string.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeReplacement.
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSTextCheckingResult.hspellCheckingResultWithRange:
Creates and returns a text checking result with the range of a misspelled word.
Parameters
- range
The range of the detected result.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeSpelling.
Availability
- Available in OS X v10.6 and later.
Declared In
NSTextCheckingResult.htransitInformationCheckingResultWithRange:components:
Creates and returns a text checking result with the specified transit information.
Parameters
- range
The range of the detected result.
- components
A dictionary containing the transit components. The currently supported keys are
NSTextCheckingAirlineKeyandNSTextCheckingFlightKey.
Return Value
Returns an NSTextCheckingResult with the specified range and a resultType of NSTextCheckingTypeTransitInformation.
Availability
- Available in OS X v10.7 and later.
Declared In
NSTextCheckingResult.hInstance Methods
rangeAtIndex:
Returns the result type that the range represents.
Parameters
- idx
The index of the result.
Return Value
The range of the result.
Discussion
A result must have at least one range, but may optionally have more (for example, to represent regular expression capture groups).
Passing rangeAtIndex: the value 0 always returns the value of the the range property. Additional ranges, if any, will have indexes from 1 to numberOfRanges-1.
Availability
- Available in OS X v10.7 and later.
Declared In
NSTextCheckingResult.hresultByAdjustingRangesWithOffset:
Returns a new text checking result after adjusting the ranges as specified by the offset.
Parameters
- offset
The amount the ranges are adjusted.
Return Value
A new NSTextCheckingResult instance with the adjusted range or ranges.
Availability
- Available in OS X v10.7 and later.
Declared In
NSTextCheckingResult.hConstants
Keys for Transit Components
The following constants identify the possible keys returned in the components dictionary.
NSString * const NSTextCheckingAirlineKey; NSString * const NSTextCheckingFlightKey;
Constants
NSTextCheckingAirlineKeyA key that corresponds to the airline of a transit result.
Available in OS X v10.7 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingFlightKeyA key that corresponds to the flight component of a transit result.
Available in OS X v10.7 and later.
Declared in
NSTextCheckingResult.h.
Keys for Address Components
The following constants identify the possible keys returned in the addressComponents dictionary.
NSString * const NSTextCheckingNameKey; NSString * const NSTextCheckingJobTitleKey; NSString * const NSTextCheckingOrganizationKey; NSString * const NSTextCheckingStreetKey; NSString * const NSTextCheckingCityKey; NSString * const NSTextCheckingStateKey; NSString * const NSTextCheckingZIPKey; NSString * const NSTextCheckingCountryKey; NSString * const NSTextCheckingPhoneKey;
Constants
NSTextCheckingNameKeyA key that corresponds to the name component of the address.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingJobTitleKeyA key that corresponds to the job component of the address.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingOrganizationKeyA key that corresponds to the organization component of the address.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingStreetKeyA key that corresponds to the street address component of the address.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingCityKeyA key that corresponds to the city component of the address.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingStateKeyA key that corresponds to the state or province component of the address.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingZIPKeyA key that corresponds to the zip code or postal code component of the address.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingCountryKeyA key that corresponds to the country component of the address.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingPhoneKeyA key that corresponds to the phone number component of the address.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.
NSTextCheckingType
These constants specify the type of checking the methods should do. They are returned by resultType.
enum {
NSTextCheckingTypeOrthography = 1ULL << 0,
NSTextCheckingTypeSpelling = 1ULL << 1,
NSTextCheckingTypeGrammar = 1ULL << 2,
NSTextCheckingTypeDate = 1ULL << 3,
NSTextCheckingTypeAddress = 1ULL << 4,
NSTextCheckingTypeLink = 1ULL << 5,
NSTextCheckingTypeQuote = 1ULL << 6,
NSTextCheckingTypeDash = 1ULL << 7,
NSTextCheckingTypeReplacement = 1ULL << 8,
NSTextCheckingTypeCorrection = 1ULL << 9,
NSTextCheckingTypeRegularExpression = 1ULL << 10
NSTextCheckingTypePhoneNumber = 1ULL << 11,
NSTextCheckingTypeTransitInformation = 1ULL << 12
};
typedef uint64_t NSTextCheckingType;
Constants
NSTextCheckingTypeOrthographyAttempts to identify the language
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypeSpellingChecks spelling.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypeGrammarChecks grammar.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypeDateAttempts to locate dates.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypeAddressAttempts to locate addresses.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypeLinkAttempts to locate URL links.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypeQuoteReplaces quotes with smart quotes.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypeDashReplaces dashes with em-dashes.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypeReplacementReplaces characters such as (c) with the appropriate symbol (in this case ©).
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypeCorrectionPerforms autocorrection on misspelled words.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypeRegularExpressionMatches a regular expression.
Available in OS X v10.7 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypePhoneNumberMatches a phone number.
Available in OS X v10.7 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingTypeTransitInformationMatches a transit information, for example, flight information.
Available in OS X v10.7 and later.
Declared in
NSTextCheckingResult.h.
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.
enum {
NSTextCheckingAllSystemTypes = 0xffffffffULL,
NSTextCheckingAllCustomTypes = 0xffffffffULL << 32,
NSTextCheckingAllTypes = (NSTextCheckingAllSystemTypes | NSTextCheckingAllCustomTypes)
};
typedef uint64_t NSTextCheckingTypes;
Constants
NSTextCheckingAllSystemTypesChecking types supported by the system. The first 32 types are reserved.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingAllCustomTypesChecking types that can be used by clients.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.NSTextCheckingAllTypesAll possible checking types, both system- and user-supported.
Available in OS X v10.6 and later.
Declared in
NSTextCheckingResult.h.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-06-11)