<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "PencilKit",
  "identifier" : "/documentation/PencilKit/PKStrokeRecognizer",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "PencilKit"
    ],
    "preciseIdentifier" : "s:9PencilKit18PKStrokeRecognizerC"
  },
  "title" : "PKStrokeRecognizer"
}
-->

# PKStrokeRecognizer

An actor that recognizes handwriting and searches for text within a PencilKit drawing.

```
final actor PKStrokeRecognizer
```

## Overview

Use `PKStrokeRecognizer` to extract recognized text from individual strokes, generate content suitable for indexing in search systems such as Spotlight, and search for specific words or phrases within handwritten content. The recognizer uses an on-device recognition engine and all operations are asynchronous.

Recognition works best when handwriting is scaled as if drawn on standard US Letter or A4 paper in points. Before creating a recognizer, check [`supportedLanguages`](/documentation/PencilKit/PKStrokeRecognizer/supportedLanguages) to confirm your target language is available. If you persist results from a recognizer, store the current [`recognitionVersion`](/documentation/PencilKit/PKStrokeRecognizer/recognitionVersion) alongside the results and regenerate them when the version advances.

## Topics

### Creating a recognizer

[`init(preferredLanguages: [Locale.Language]?)`](/documentation/PencilKit/PKStrokeRecognizer/init(preferredLanguages:))

Creates a recognizer with the specified preferred languages.

### Providing drawing content

[`var drawing: PKDrawing`](/documentation/PencilKit/PKStrokeRecognizer/drawing)

The drawing the recognizer analyzes.

[`func updateDrawing(PKDrawing) async`](/documentation/PencilKit/PKStrokeRecognizer/updateDrawing(_:))

Updates the drawing the recognizer analyzes.

### Recognizing handwriting

[`func recognizedText(strokeIDs: Set<UUID>?) async -> String?`](/documentation/PencilKit/PKStrokeRecognizer/recognizedText(strokeIDs:))

Returns the recognized text from the specified strokes in the drawing.

[`var indexableContent: String?`](/documentation/PencilKit/PKStrokeRecognizer/indexableContent)

A string suitable for indexing the drawing’s recognized text in search systems such as Spotlight.

### Searching for text

[`func search(String, fullWordsOnly: Bool, caseMatchingOnly: Bool) async -> [PKStrokeRecognizer.SearchResult]`](/documentation/PencilKit/PKStrokeRecognizer/search(_:fullWordsOnly:caseMatchingOnly:))

Searches the drawing for strokes whose recognized text matches the query.

[`struct SearchResult`](/documentation/PencilKit/PKStrokeRecognizer/SearchResult)

A value that describes a single result returned by a handwriting search.

### Checking language support

[`static var supportedLanguages: Set<Locale.Language>`](/documentation/PencilKit/PKStrokeRecognizer/supportedLanguages)

The languages the recognizer supports.

[`var languages: [Locale.Language]`](/documentation/PencilKit/PKStrokeRecognizer/languages)

The languages the recognizer uses, ordered by descending priority.

[`static var recognitionVersion: Int`](/documentation/PencilKit/PKStrokeRecognizer/recognitionVersion)

The version number of the recognition engine.

## Relationships

### Conforms To

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

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

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

---

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)