MLKitDigitalInkRecognition Framework Reference

  • DigitalInkRecognizer is an object used for performing handwriting recognition on digital ink, which is a vector representation of user writing composed of strokes and touch points.

  • It is initialized using digitalInkRecognizer(options:) with specified options for customization.

  • The primary functions are recognize(ink:) and recognize(ink:context:) for performing handwriting recognition, with the latter allowing for a recognition context to improve accuracy.

  • Using a DigitalInkRecognitionContext with recognize(ink:context:) can provide better accuracy by considering the writing area and pre-existing text.

DigitalInkRecognizer

class DigitalInkRecognizer : NSObject

Object to perform handwriting recognition on digital ink.

Digital ink is the vector representation of what a user has written. It is composed of a sequence of strokes, each being a sequence of touch points (coordinates and timestamp). See Ink for details.

  • Unavailable. Use digitalInkRecognizer(options:) instead.

  • Creates a DigitalInkRecognizer object using the specified options.

    See DigitalInkRecognizerOptions for details.

    Declaration

    Swift

    class func digitalInkRecognizer(options: MLKDigitalInkRecognizerOptions) -> DigitalInkRecognizer
  • Performs a recognition of the input ink.

    Note that using recognize(ink:context:completion:) instead of this method may lead to better accuracy in some cases.

    Declaration

    Swift

    func recognize(ink: MLKInk) async throws -> MLKDigitalInkRecognitionResult

    Parameters

    ink

    Input to be recognized.

    completion

    A callback for returning recognition candidates. See DigitalInkRecognizerCallback for details.

  • Performs a recognition of the input ink using a recognition context.

    A recognition context contains information about the size of the writing area, and the characters that have already been entered in the text area. This helps disambiguate certain cases.

    Example usage: a previous recognition has yielded the string “hello”, that has been inserted in a text field. The user then handwrites “world”. Send the present method the ink showing “world”, and “hello” as a string in context. The recognizer will most likely return the string “ world” with a leading space separating the two words.

    See DigitalInkRecognitionContext for details.

    Declaration

    Swift

    func recognize(ink: MLKInk, context: MLKDigitalInkRecognitionContext) async throws -> MLKDigitalInkRecognitionResult

    Parameters

    ink

    Input to be recognized.

    context

    See DigitalInkRecognitionContext for details.

    completion

    A callback for returning recognition candidates. See DigitalInkRecognizerCallback for details. If nothing can be recognized, an empty list of candidates will be passed to the callback.