MailComposer didFinish Doesn't work with results in Swift 3.0

I converted my application to swift 3.0 and have a problem with MailComposeController . When I call the function:

 `func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?){ controller.dismiss(animated: true, completion: nil) }` 

First of all, I have an error with the information: enter image description here

which is strange for me because I copy and paste this method from MFMailComposeViewControllerDelegate . When I change Error to NSError , it works, but I get a warning with information, this method must be private to avoid this warning.

When I am in mailComposer and see the email and try to click Cancel , this controller will not disappear. Any solution how to reject this controller?

+5
source share
1 answer

I had the same problem because I imported RealmSwift , which has its own Error structure.

Correct it by indicating what type of error you want. In this case, Swift.Error .

Full code:

  func mailComposeController (_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Swift.Error?) {
     controller.dismiss (animated: true, completion: nil)
 }
+10
source

All Articles