Search code examples
iosobjective-ccocoa-touchcompiler-warningssentinel

Missing sentinel at method dispatch although nil is present in argument list


I want to create a UIActionSheet but I always get a warning about a "missing sentinel":

/Users/....mm:136:173: warning: missing sentinel in method dispatch [-Wsentinel]

UIActionSheet* adsl_action_sheet = [[[UIActionSheet alloc] initWithTitle:nil 
                                                                delegate:(id<UIActionSheetDelegate>)self 
                                                       cancelButtonTitle:[dsd_string_localizer ms_get_localized_system_string:@"Cancel"] 
                                                  destructiveButtonTitle:nil 
                                                       otherButtonTitles:[dsd_string_localizer ms_get_localized_system_string:@"Logoff"], [dsd_string_localizer ms_get_localized_system_string:@"Disconnect"], nil] autorelease];

I really can't see anything wrong... maybe I'm just blind.

The file containing this code is an Objective-C++ file.

I also noticed that it is showing these "Sentinel Warnings" at every place which needs such a sentinel.


Solution

  • You need to cast that final "sentinel" nil to the correct type, using:

    ... , (NSString *)nil] autorelease];
    //    ^^^^^^^^^^^^
    

    However, I am not certain why the compiler requires this cast.

    I believe this is necessary when compiling with -Wstrict-null-sentinel (waiting for confirmation from OP).