A position and orientation of something of interest in the physical environment.


class ARAnchor : NSObject


To track the static positions and orientations of real or virtual objects relative to the camera, create anchor objects and use the add(anchor:) method to add them to your AR session.

Some ARKit features automatically add special anchors to a session. World-tracking sessions can add ARPlaneAnchor, ARObjectAnchor, and ARImageAnchor objects if you enable the corresponding features; face-tracking sessions add ARFaceAnchor objects.

Subclassing Notes

In addition to creating your own ARAnchor instances to track the real-world positions of your virtual content, you can also subclass ARAnchor to associate custom data with anchors you create. Ensure that your anchor classes behave correctly when ARKit updates frames or saves and loads anchors in an ARWorldMap:

  • Anchor subclasses must fullfill the requirements of the ARAnchorCopying protocol. ARKit calls init(anchor:) (on a background thread) to copy instances of your anchor class from each ARFrame to the next. Your implementation of this initializer should copy the values of any custom properties your subclass adds.

  • Anchor subclasses must also adopt the NSSecureCoding protocol. Override encode(with:) and init(coder:) to save and restore the values your subclass' custom properties when ARKit saves and loads them in a world map.

  • Anchors are considered equal based on their identifier property.

  • Only anchors that do not adopt ARTrackable are included when you save a world map.


Creating Anchors

init(transform: simd_float4x4)

Creates a new anchor object with the specified transform.

init(name: String, transform: simd_float4x4)

Creates a new anchor object with the specified transform and a descriptive name.

var name: String?

A descriptive name for the anchor.

Tracking Anchors

var identifier: UUID

A unique identifier for the anchor.

var sessionIdentifier: UUID?

The unique identifier of the session that owns this anchor.

var transform: simd_float4x4

A matrix encoding the position, orientation, and scale of the anchor relative to the world coordinate space of the AR session the anchor is placed in.


protocol ARAnchorCopying

Support for custom ARAnchor subclasses.

protocol ARTrackable

A real-world object in a scene for which ARKit tracks changes to position and orientation.

See Also


Choosing Which Camera Feed to Augment

Augment the user's environment through either the front or back camera.

Verifying Device Support and User Permission

Check whether your app can use ARKit and respect user privacy at runtime.

Managing Session Lifecycle and Tracking Quality

Keep the user informed on the current session state and recover from interruptions.

class ARSession

The main object you use to control an AR experience.

class ARConfiguration

An object that defines the particular ARKit features enabled in your session at a given time.