1

It looks like the GoogleCast SDK for iOS (at least version 3.3.0 we shipped the previous version with; maybe this has been fixed in a more recent version we've upgraded to since, but I'd like to be sure) is sometimes sending nils to a delegate when reporting errors, even though the annotation claims it's nonnull. This, in turn, makes our Swift code crash when we try to look at the error.

Is there any way to override the nullability annotation in the header, assuming I don't want to touch the upstream header? If I just define my delegate method to receive an Error?, I get a warning.

Juri Pakaste
  • 1,402
  • 10
  • 15

1 Answers1

0

If the header is wrapped in NS_ASSUME_NONNULL_BEGIN/NS_ASSUME_NONNULL_END, and there are no other nullable pointers in the header, then you could make a wrapper header that undefines that macro and redefines it at the end. Something like:

#ifdef NS_ASSUME_NONNULL_BEGIN
#undef NS_ASSUME_NONNULL_BEGIN
#endif 
#ifdef NS_ASSUME_NONNULL_END
#undef NS_ASSUME_NONNULL_END
#endif

#import "header with bogus prototype.h"

#ifndef NS_ASSUME_NONNULL_BEGIN
#define NS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
#endif
#ifndef NS_ASSUME_NONNULL_END
#define NS_ASSUME_NONNULL_END   _Pragma("clang assume_nonnull end")
#endif

You'd have to update your code to always include your wrapper header instead of the real header in this scenario.

Unfortunately, if there are any other nullability annotations, then all pointer arguments in the header have to have their nullability defined.

user1118321
  • 25,567
  • 4
  • 55
  • 86