Jason Tyler Jason Tyler - 1 year ago 262
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.


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)")
self.dismissViewControllerAnimated(true, completion: nil)

Answer Source

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

switch result {
case .Cancelled: // something
case .Saved: // something
// .. and so on
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download