Mac Developer Library

Developer

Foundation Framework Reference NSTextCheckingResult Class Reference

Options
Deployment Target:

On This Page
Language:

NSTextCheckingResult

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.6 and later.

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.

  • range range Property

    Returns the range of the result that the receiver represents. (read-only)

    Declaration

    Swift

    var range: NSRange { get }

    Objective-C

    @property(readonly) NSRange range

    Discussion

    This property will be present for all returned NSTextCheckingResult instances.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

    See Also

    resultType

  • Returns the text checking result type that the receiver represents. (read-only)

    Declaration

    Swift

    var resultType: NSTextCheckingType { get }

    Objective-C

    @property(readonly) NSTextCheckingType resultType

    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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • Returns the number of ranges. (read-only)

    Declaration

    Swift

    var numberOfRanges: Int { get }

    Objective-C

    @property(readonly) NSUInteger numberOfRanges

    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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • Returns the result type that the range represents.

    Declaration

    Swift

    func rangeAtIndex(_ idx: Int) -> NSRange

    Objective-C

    - (NSRange)rangeAtIndex:(NSUInteger)idx

    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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    class func grammarCheckingResultWithRange(_ range: NSRange, details details: [AnyObject]) -> NSTextCheckingResult

    Objective-C

    + (NSTextCheckingResult *)grammarCheckingResultWithRange:(NSRange)range details:(NSArray *)details

    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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

    See Also

    grammarDetails

  • The details of a located grammatical type checking result. (read-only)

    Declaration

    Swift

    var grammarDetails: [AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSArray *grammarDetails

    Discussion

    This array of strings is suitable for presenting to the user.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    func resultByAdjustingRangesWithOffset(_ offset: Int) -> NSTextCheckingResult

    Objective-C

    - (NSTextCheckingResult *)resultByAdjustingRangesWithOffset:(NSInteger)offset

    Parameters

    offset

    The amount the ranges are adjusted.

    Return Value

    A new NSTextCheckingResult instance with the adjusted range or ranges.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    let NSTextCheckingAirlineKey: String let NSTextCheckingFlightKey: String

    Objective-C

    NSString * const NSTextCheckingAirlineKey; NSString * const NSTextCheckingFlightKey;

    Constants

    • NSTextCheckingAirlineKey

      NSTextCheckingAirlineKey

      A key that corresponds to the airline of a transit result.

      Available in OS X v10.7 and later.

    • NSTextCheckingFlightKey

      NSTextCheckingFlightKey

      A key that corresponds to the flight component of a transit result.

      Available in OS X v10.7 and later.

  • The following constants identify the possible keys returned in the addressComponents dictionary.

    Declaration

    Swift

    let NSTextCheckingNameKey: String let NSTextCheckingJobTitleKey: String let NSTextCheckingOrganizationKey: String let NSTextCheckingStreetKey: String let NSTextCheckingCityKey: String let NSTextCheckingStateKey: String let NSTextCheckingZIPKey: String let NSTextCheckingCountryKey: String let NSTextCheckingPhoneKey: String

    Objective-C

    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

    • NSTextCheckingNameKey

      NSTextCheckingNameKey

      A key that corresponds to the name component of the address.

      Available in OS X v10.6 and later.

    • NSTextCheckingJobTitleKey

      NSTextCheckingJobTitleKey

      A key that corresponds to the job component of the address.

      Available in OS X v10.6 and later.

    • NSTextCheckingOrganizationKey

      NSTextCheckingOrganizationKey

      A key that corresponds to the organization component of the address.

      Available in OS X v10.6 and later.

    • NSTextCheckingStreetKey

      NSTextCheckingStreetKey

      A key that corresponds to the street address component of the address.

      Available in OS X v10.6 and later.

    • NSTextCheckingCityKey

      NSTextCheckingCityKey

      A key that corresponds to the city component of the address.

      Available in OS X v10.6 and later.

    • NSTextCheckingStateKey

      NSTextCheckingStateKey

      A key that corresponds to the state or province component of the address.

      Available in OS X v10.6 and later.

    • NSTextCheckingZIPKey

      NSTextCheckingZIPKey

      A key that corresponds to the zip code or postal code component of the address.

      Available in OS X v10.6 and later.

    • NSTextCheckingCountryKey

      NSTextCheckingCountryKey

      A key that corresponds to the country component of the address.

      Available in OS X v10.6 and later.

    • NSTextCheckingPhoneKey

      NSTextCheckingPhoneKey

      A key that corresponds to the phone number component of the address.

      Available in OS X v10.6 and later.

  • These constants specify the type of checking the methods should do. They are returned by resultType.

    Declaration

    Swift

    struct NSTextCheckingType : RawOptionSetType { init(_ rawValue: UInt64) init(rawValue rawValue: UInt64) static var Orthography: NSTextCheckingType { get } static var Spelling: NSTextCheckingType { get } static var Grammar: NSTextCheckingType { get } static var Date: NSTextCheckingType { get } static var Address: NSTextCheckingType { get } static var Link: NSTextCheckingType { get } static var Quote: NSTextCheckingType { get } static var Dash: NSTextCheckingType { get } static var Replacement: NSTextCheckingType { get } static var Correction: NSTextCheckingType { get } static var RegularExpression: NSTextCheckingType { get } static var PhoneNumber: NSTextCheckingType { get } static var TransitInformation: NSTextCheckingType { get } }

    Objective-C

    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

    • Orthography

      NSTextCheckingTypeOrthography

      Attempts to identify the language

      Available in OS X v10.6 and later.

    • Spelling

      NSTextCheckingTypeSpelling

      Checks spelling.

      Available in OS X v10.6 and later.

    • Grammar

      NSTextCheckingTypeGrammar

      Checks grammar.

      Available in OS X v10.6 and later.

    • Date

      NSTextCheckingTypeDate

      Attempts to locate dates.

      Available in OS X v10.6 and later.

    • Address

      NSTextCheckingTypeAddress

      Attempts to locate addresses.

      Available in OS X v10.6 and later.

    • Link

      NSTextCheckingTypeLink

      Attempts to locate URL links.

      Available in OS X v10.6 and later.

    • Quote

      NSTextCheckingTypeQuote

      Replaces quotes with smart quotes.

      Available in OS X v10.6 and later.

    • Dash

      NSTextCheckingTypeDash

      Replaces dashes with em-dashes.

      Available in OS X v10.6 and later.

    • Replacement

      NSTextCheckingTypeReplacement

      Replaces characters such as (c) with the appropriate symbol (in this case ©).

      Available in OS X v10.6 and later.

    • Correction

      NSTextCheckingTypeCorrection

      Performs autocorrection on misspelled words.

      Available in OS X v10.6 and later.

    • RegularExpression

      NSTextCheckingTypeRegularExpression

      Matches a regular expression.

      Available in OS X v10.7 and later.

    • PhoneNumber

      NSTextCheckingTypePhoneNumber

      Matches a phone number.

      Available in OS X v10.7 and later.

    • TransitInformation

      NSTextCheckingTypeTransitInformation

      Matches a transit information, for example, flight information.

      Available in OS X v10.7 and later.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • 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.

    Declaration

    Swift

    typealias NSTextCheckingTypes = UInt64

    Objective-C

    enum { NSTextCheckingAllSystemTypes = 0xffffffffULL, NSTextCheckingAllCustomTypes = 0xffffffffULL << 32, NSTextCheckingAllTypes = (NSTextCheckingAllSystemTypes | NSTextCheckingAllCustomTypes ) }; typedef uint64_t NSTextCheckingTypes;

    Constants

    • NSTextCheckingAllSystemTypes

      NSTextCheckingAllSystemTypes

      Checking types supported by the system. The first 32 types are reserved.

      Available in OS X v10.6 and later.

    • NSTextCheckingAllCustomTypes

      NSTextCheckingAllCustomTypes

      Checking types that can be used by clients.

      Available in OS X v10.6 and later.

    • NSTextCheckingAllTypes

      NSTextCheckingAllTypes

      All possible checking types, both system- and user-supported.

      Available in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.