<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSDataDetector/init(types:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDataDetector(im)initWithTypes:error:"
  },
  "title" : "init(types:)"
}
-->

# init(types:)

Initializes and returns a data detector instance.

```
init(types checkingTypes: NSTextCheckingTypes) throws
```

## Parameters

`checkingTypes`

The checking types. The supported checking types are a subset of the types [`NSTextCheckingResult.CheckingType`](/documentation/Foundation/NSTextCheckingResult/CheckingType). Those constants can be combined using the C-bitwise OR operator.

## Return Value

Returns the newly initialized data detector. If an error was encountered returns `nil`, and `error` contains the error.

## Discussion

Currently, the supported data detectors `checkingTypes` are:  [`date`](/documentation/Foundation/NSTextCheckingResult/CheckingType/date), [`address`](/documentation/Foundation/NSTextCheckingResult/CheckingType/address), [`link`](/documentation/Foundation/NSTextCheckingResult/CheckingType/link), `NSTextCheckingTypePhoneNumber`, and `NSTextCheckingTypeTransitInformation`.

> Handling Errors in Swift:
> In Swift, this API is imported as an initializer and is marked with the `throws` keyword to indicate that it throws an error in cases of failure.
> 
> You call this method in a `try` expression and handle any errors in the `catch` clauses of a `do` statement, as described in [Error Handling](https://docs.swift.org/swift-book/LanguageGuide/ErrorHandling.html) in [The Swift Programming Language](https://docs.swift.org/swift-book/) and `About Imported Cocoa Error Parameters`.

## See Also

[`checkingTypes`](/documentation/Foundation/NSDataDetector/checkingTypes)

Returns the checking types for the data detector.

[`dataDetectorWithTypes:error:`](/documentation/Foundation/NSDataDetector/dataDetectorWithTypes:error:)

Creates and returns a new data detector instance.



---

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)