<!--
{
  "availability" : [
    "macOS: 15.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreHID",
  "identifier" : "/documentation/CoreHID/HIDElement/Value/logicalValue(asTypeTruncatingIfNeeded:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core HID",
      "CoreHID"
    ],
    "preciseIdentifier" : "s:7CoreHID10HIDElementV5ValueV07logicalD024asTypeTruncatingIfNeededxSgxm_ts17FixedWidthIntegerRzlF"
  },
  "title" : "logicalValue(asTypeTruncatingIfNeeded:)"
}
-->

# logicalValue(asTypeTruncatingIfNeeded:)

The raw value of the data cast as an integer type and bound by the [`HIDElement`](/documentation/CoreHID/HIDElement)’s logical minimum and logical maximum values.

```
func logicalValue<IntegerType>(asTypeTruncatingIfNeeded: IntegerType.Type) -> IntegerType? where IntegerType : FixedWidthInteger
```

## Parameters

`asTypeTruncatingIfNeeded`

The type to which to cast the underlying bytes before applying bounds, truncating or extending the bytes as necessary.

## Return Value

The data cast as the requested type, or nil if out of bounds.

## Discussion

If the raw value is out of bounds, this returns `nil`.
For example, if the logical minimum and logical maximum are specified as `1` and `127` respectively, and the raw value is `0`, the logical value is undefined.

---

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)