John Cashew John Cashew - 1 year ago 122
Objective-C Question

How to get rid of nullability warning in an objective c typedef?

This code produces a "pointer is missing a nullability type specifier" warning in XCode and I can't guess how to silence the warning.


@interface MyClass : NSObject

typedef id (^MyBlock)(id object);



The following don't silence the warning:

typedef __nonnull id (^MyBlock)(__nonnull id object);
typedef nonnull id (^MyBlock)(nonnull id object);

I would appreciate any suggestions.

Thank you.

Answer Source

typedef types don’t usually have an inherent nullability—they can easily be either nullable or non-nullable depending on the context. Therefore, typedef types are not assumed to be nonnull, even within audited regions.

Below syntax is working fine

typedef __nonnull id (^MyBlock)(__nonnull id object);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download