Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointer is missing a nullability type specifier on function interface

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

enter image description here

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?

like image 426
Yuchen Avatar asked Oct 09 '15 02:10

Yuchen


1 Answers

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.

like image 56
matt Avatar answered Oct 23 '22 02:10

matt