Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use nullable/nonnull in implementation file

Tags:

objective-c

I want to use Objective-C nullability feature. But should I annotate with nullable/nonnull implementation file or only interface?

like image 996
rabbitinspace Avatar asked Jul 01 '15 20:07

rabbitinspace


Video Answer


1 Answers

The only reason to declare nullability is to have warning feedbacks from the compiler unit (see https://developer.apple.com/swift/blog/?id=25 ).

As a best practice, you should always set nullable and nonnull (or _Nullable and _Nonnull) in your declarations.

So you should do this for all your interfaces, but depending on your coding standards, you may implement class-scoped (or category-scoped) methods without declaring them, and in that case the declaration IS the implementation and you should declare their nullability values.

You always can declare nullability for implementations that are declared in interfaces, but in my opinion it degrades maintainability.

like image 57
Pierre Mardon Avatar answered Nov 07 '22 19:11

Pierre Mardon