John Cashew John Cashew - 1 month ago 9
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.

NS_ASSUME_NONNULL_BEGIN

@interface MyClass : NSObject

typedef id (^MyBlock)(id object);

@end

NS_ASSUME_NONNULL_END


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

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);
Comments