Home

nonnull

Nonnull refers to a nullability annotation used in some programming languages, notably Objective-C and C, to indicate that a pointer or return value must not be null. It is part of a broader set that also includes nullable and null_unspecified. These annotations help static analysis tools detect potential null dereferences and assist with interoperability with Swift, where nullability affects whether a value is imported as an optional.

In Objective-C, nullability annotations are applied to pointer types and can be combined with macros that control

Beyond Objective-C, the term also appears in C/C++ contexts via the Clang/GCC attribute __attribute__((nonnull)) that can

Nullability annotations are primarily a development-time aid rather than runtime checks. They do not automatically enforce

See also: nullability, nullable, nonnull in various languages, Swift interoperability, static analysis, ARC.

default
assumptions.
Common
forms
include
_Nonnull
and
_Nullable
type
qualifiers,
as
well
as
__nonnull
and
__nullable
attributes.
Developers
often
wrap
header
files
with
NS_ASSUME_NONNULL_BEGIN
and
NS_ASSUME_NONNULL_END
to
assume
nonnull
by
default,
then
use
nullable
annotations
to
override
as
needed.
For
example,
a
method
parameter
of
a
nonnull
string
would
be
declared
as
NSString
*
_Nonnull
name.
be
attached
to
function
parameters
or
the
return
value
(via
returns_nonnull)
to
enforce
non-null
usage
at
compile
time.
These
attributes
can
specify
which
parameters
must
be
non-null
by
index,
enabling
more
precise
static
analysis
and
optimization.
non-null
values
during
execution,
but
they
guide
developers,
enable
safer
API
design,
and
improve
correctness
when
bridging
to
Swift.
Misuse
can
still
lead
to
null
dereferences
if
runtime
checks
are
not
performed.