Jason Tyler Jason Tyler - 24 days ago 120
Swift Question

MFMailComposeResult constants don't compile in Swift 2.3

I updated to XCode 8 this morning and chose to convert my Swift files to 2.3 rather than 3. I have resolved all of my compilation issues, except for the code below. Only the MFMailComposeResultSent case actually does anything important. XCode says MFMailComposeResultSent and the other similar cases are unresolved identifiers. The latest documentation shows I should be using MFMailComposeResult.sent, and the auto-suggest feature offers this as a possibility, but it also refuses to compile. I'd be grateful for info on how to make this compile for use with Swift 2.3.

Thanks.

func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError?) {
switch result.rawValue {
case MFMailComposeResultCancelled.rawValue:
print("Mail canceled")
case MFMailComposeResultSaved.rawValue:
print("Mail saved")
case MFMailComposeResultSent.rawValue:
makeToast("Successfully sent email.", duration: 3)
print("Mail sent")
case MFMailComposeResultFailed.rawValue:
print("Mail sent failure: \(error!.localizedDescription)")
default:
break
}
hideActivityIndicator()
self.dismissViewControllerAnimated(true, completion: nil)
}

Answer

What is with the rawValue everywhere? Just switch on the cases. Like this:

switch result {
case .Cancelled: // something
case .Saved: // something
// .. and so on
Comments