<!--
{
  "documentType" : "article",
  "framework" : "Xcode",
  "identifier" : "/documentation/Xcode/nonnull-variable-assignment-violation",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Nonnull variable assignment violation"
}
-->

# Nonnull variable assignment violation

Detects when you incorrectly assign null to a variable.

## Overview

Use this check to detect when you assign `null` to a variable with the `_Nonnull` annotation. Available in Xcode 9 and later.

> Note: The nonnull violation check for variable assignment is off by default. You can turn it on by enabling the `-fsanitize=nullability-assign` compiler flag.

### Violation of nonnull annotation with variable assignment in C

In the following example, the call to `assigns_a_value` breaks the `_Nonnull` annotation of the variable `q`:

```occ
void assigns_a_value(int *p) {     
    int *_Nonnull q = p; // Warning: null can be assigned
}
assigns_a_value(NULL); // Error: _Nonnull variable violation
```

#### Solution

Correct logic errors, or remove the `_Nonnull` annotation.

---

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)