Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumeration value 'SHKShareTypeUndefined' not handled in switch

I get the warning Enumeration value 'SHKShareTypeUndefined' not handled in switch in the below code. I bolded the relevant line and pointer:

    + (NSArray *)favoriteSharersForType:(SHKShareType)type
{   
    NSArray *favoriteSharers = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@%i", SHK_FAVS_PREFIX_KEY, type]];

    // set defaults
    if (favoriteSharers == nil)
    {
        switch (type) 
        {
            case SHKShareTypeURL:
                favoriteSharers = [NSArray arrayWithObjects:@"SHKTwitter",@"SHKFacebook",@"SHKReadItLater",nil];
                break;

            case SHKShareTypeImage:
                favoriteSharers = [NSArray arrayWithObjects:@"SHKMail",@"SHKFacebook",@"SHKCopy",nil];
                break;

            case SHKShareTypeText:
                favoriteSharers = [NSArray arrayWithObjects:@"SHKMail",@"SHKTwitter",@"SHKFacebook", nil];
                break;

            case SHKShareTypeFile:
                favoriteSharers = [NSArray arrayWithObjects:@"SHKMail", nil];
                break;

            case SHKShareTypeUndefined:         
                break;
        }

        // Save defaults to prefs
        [self setFavorites:favoriteSharers forType:type];
    }

This warning is in ShareKit and I am not sure how to fix it.

Thanks!

like image 463
SimplyKiwi Avatar asked Aug 09 '11 12:08

SimplyKiwi


3 Answers

Add dummy case for that enum value:

case SHKShareTypeUndefined:         
     break;

Or set your "Check switch statements" flag to NO in your target settings (warnings section)

like image 113
Vladimir Avatar answered Oct 31 '22 23:10

Vladimir


You can also use a default case:

switch (type) {
        case SHKShareTypeURL:
            favoriteSharers = ...
            break;

        // ...

        default:
           NSLog(@"Unexpected case - will do nothing here");
           break;
} 
like image 32
Guillaume Avatar answered Oct 31 '22 23:10

Guillaume


If you have reason to want neither to add cases for all values of the enum nor to add a default case, and if you're compiling with clang, you can write

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wswitch"

switch (type) {
    //...
}

#pragma clang diagnostic pop
like image 4
Nate Chandler Avatar answered Oct 31 '22 23:10

Nate Chandler