Xcode 4.4 Warning: Case value not in enumerated type 'MessageComposeResult' (aka 'enum MessageComposeResult')

1.5k Views Asked by At

Anyone else getting this warning in Xcode 4.4?

Case value not in enumerated type 'MessageComposeResult' (aka 'enum MessageComposeResult')

MFMailComposeResultFailed is included in Result codes returned when the mail composition interface is dismissed in the documentation. However, the documentation lists it but the GCC warns it is NOT an enum within MessageComposeResult. Why?

    case MFMailComposeResultFailed:{
        //do something here
    }
        break;

Here is the expanded Method in which this case is called (I have commented this enum out to disable the warning):

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {

UIAlertView *errormsg = nil;
// Notifies users about errors associated with the interface
switch (result)
{
    case MFMailComposeResultCancelled:
    {
        //Do something, If you need to
        NSString *msgtitle = @"Cancelled Mail";
        NSString *Bodymsg = @"Email Has been Cancelled by USER. You may continue to make modifications to the current attendance data at this point.";
        errormsg = [[UIAlertView alloc] initWithTitle:msgtitle message:Bodymsg delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
    }
        break;
    case MFMailComposeResultSaved:{/*Do nothing at this point*/}
        break;
         //NOTE: MFMailComposeResultFailed is included in Result codes returned when the mail composition interface is dismissed. However the documentation lists it but the GCC warns it is NOT an enum within MessageComposeResult. May be an Apple Bug.
    /*case MFMailComposeResultFailed:{
        NSString *title = @"Unable to Send Mail";
        NSString *msg = @"Failed:\nmessage was not saved or queued, possibly due to an error.\nCheck your mail sent or draft items.";
        errormsg = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
    }
        break;
       */  
    case MFMailComposeResultSent:{
        NSString *title = @"Mail Sent";
        NSString *msg = @"Attendance Email has been sent. Thank you.";

        errormsg = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
        //clean up data
        //code here irrelevant
        //set a completed flag for sent email in system

        //display Alert and dismiss the mail composer view here
        UIAlertView *alertView = nil;

        if (result) {
            alertView = [[UIAlertView alloc] initWithTitle:@"AttendanceViewController: viewDidLoad" message:@"updateProgressOfClassInstance FAILED" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        }
        if (alertView != nil) {
            [alertView show];
        }

    }
        break;
    default:
        break;
}
//dismiss view and display any errors here.
[self dismissModalViewControllerAnimated:YES];
if (errormsg != nil) {
    [errormsg show];
}

I hope this clarifies it for you guys. Thanks!

(UPDATE) Ok there were several issues with my code that I didn't realize was there. I fixed them and here below is the resultant correct switch statement.

switch (result)
{
    case MessageComposeResultCancelled:
    {
        //Do something, If you need to!
    }
        break;

    case MessageComposeResultFailed:{
        //Do something else, If you need to!!
    }
        break;

    case MessageComposeResultSent:{
        //Do something user friendly, If you need to!

    }
        break;

    default:
        break;
}

Keep on rockin' in the free world and on stackoverflow! Woot!

1

There are 1 best solutions below

1
On BEST ANSWER

You are mixing up error codes. The result enum has the three values that you see working.

The "MFMailComposeResultFailed" value is returned within the error of this delegate method:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error

Look at the bottom of this deocumentation page:

MFMailComposeViewController Class Reference