Originally, I have something very simple as the following. A custom category of UIAlertAction
so that I can create a okay action simply by [UIAlertAction okay]
;
@interface UIAlertAction (Custom)
+ (UIAlertAction *)okay;
@end
@implementation UIAlertAction (Custom)
+ (UIAlertAction *)okay
{
return [UIAlertAction actionWithTitle:@"Ok"
style:UIAlertActionStyleCancel
handler:nil];
}
@end
And later on, I decide that I also want one with a complete hander so the interface become this:
@interface UIAlertAction (Custom)
+ (UIAlertAction *)okay;
+ (UIAlertAction *)okayWithHandler:(void (^ __nullable)(UIAlertAction *action))handler;
@end
And and I start getting warning message on the fist line:
Pointer is missing a nullability type specifier
I think understand the idea of nullable (honestly, the name is pretty descriptive). But what I don't understand is why adding a __nullable
on the second function will make it necessary to have nullable specifier for the first one?
But what I don't understand is why adding a __nullable on the second function will make it necessary to have nullable specifier for the first one?
It's simply because as soon as you supply any nullability information in a header, you are expected to supply nullability information for everything in that header. Either the whole API is unspecified or the whole API is specified, with regard to nullability. The compiler is just warning you that you have left the job half-finished.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With