<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreMotion",
  "identifier" : "/documentation/CoreMotion/CMDeviceMotionHandler",
  "metadataVersion" : "0.1.0",
  "role" : "Type Alias",
  "symbol" : {
    "kind" : "Type Alias",
    "modules" : [
      "Core Motion"
    ],
    "preciseIdentifier" : "c:@T@CMDeviceMotionHandler"
  },
  "title" : "CMDeviceMotionHandler"
}
-->

# CMDeviceMotionHandler

The type of block callback for handling device-motion data.

```
typealias CMDeviceMotionHandler = (CMDeviceMotion?, (any Error)?) -> Void
```

## Discussion

Blocks of type `CMDeviceMotionHandler` are called when there is device-motion data to process. You pass the block into [`startDeviceMotionUpdates(to:withHandler:)`](/documentation/CoreMotion/CMMotionManager/startDeviceMotionUpdates(to:withHandler:)) as the second argument. Blocks of this type return no value but take two arguments:

- `motion`: A [`CMDeviceMotion`](/documentation/CoreMotion/CMDeviceMotion) object, which encapsulates other objects and a structure representing attitude, rotation rate, gravity, and user acceleration.
- `error`: An error object representing an error encountered in providing device-motion data. If an error occurs, you should stop device-motion data updates and inform the user of the problem. If there is no error, this argument is `nil`. Core Motion errors are of the [`CMErrorDomain`](/documentation/CoreMotion/CMErrorDomain) domain and the [`CMError`](/documentation/CoreMotion/CMError) type.

---

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)