Contents

subject(at:)

Returns the subject at the given point within the interaction’s image, if one exists.

Declaration

@MainActor final func subject(at point: CGPoint) async -> ImageAnalysisInteraction.Subject?

Parameters

  • point:

    A point in view coordinates at which to select a subject.

Return Value

The subject that resides at point; or, nil, if no subject resides at point.

Discussion

This method works for interaction types that include imageSubject.

The following code retrieves a subject image given a screen point, for instance, where a person taps:

let configuration = ImageAnalyzer.Configuration()
...
interaction.preferredInteractionTypes = [.imageSubject]
...
let viewPoint = /* A point in view coordinates */
if let subjectObject = try await interaction.subject(at: viewPoint) {
    if let image = subjectObject.image {
        // Do something with the subject image.
    }
}

See Also

Accessing image subjects