<!--
{
  "documentType" : "article",
  "framework" : "Xcode",
  "identifier" : "/documentation/Xcode/invalid-boolean",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Invalid Boolean value"
}
-->

# Invalid Boolean value

Detects when a program accesses a Boolean variable and its value isn’t true or false.

## Overview

Use this check to detect accesses to a Boolean variable when its value isn’t true or false. This problem can occur when using an integer or pointer without an appropriate cast. The use of out-of-range Boolean values has undefined behavior, which can be difficult to debug. Available in Xcode 9 and later.

### Invalid Boolean variable access in C

The intent of the following code is to call the `success` function when `result` is nonzero. However, because it uses a Boolean check, the compiler may, as an optimization, only emit instructions that check the least-significant bit of `predicate`, which is `0`, causing a logic error.

```occ
int result = 2;
bool *predicate = (bool *)&result;
if (*predicate) { // Error: variable is not a valid Boolean
    success();
}
```

#### Solution

Use integer comparison instead of a Boolean check.

```occ
int result = 2;
if (result != 0) { // Correct
  success();
}
```

---

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)