This is sample code:
import UIKit
import MessageUI
class ViewController: UIViewController, MFMailComposeViewControllerDelegate {
@IBAction func showEmail(sender : AnyObject) {
var emailTitle = "Test Email"
var messageBody = "This is a test email body"
var toRecipents = ["[email protected]"]
var mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(emailTitle)
mc.setMessageBody(messageBody, isHTML: false)
mc.setToRecipients(toRecipents)
self.presentViewController(mc, animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError) {
switch result {
case MFMailComposeResultCancelled:
NSLog("Mail cancelled")
case MFMailComposeResultSaved:
NSLog("Mail saved")
case MFMailComposeResultSent:
NSLog("Mail sent")
case MFMailComposeResultFailed:
NSLog("Mail sent failure: %@", [error.localizedDescription])
default:
break
}
self.dismissViewControllerAnimated(false, completion: nil)
}
}
In function mailComposeController I get an error on every case expression:
Could not find an overload '~=' that accepts the supplied arguments.
What am I doing wrong?
switch
cases into Swift-conform? likecase MFMailComposeResult.Cancelled:
ect...? I could not find the reference about thisenum
in Swift, so my idea would rather be a question than a pure solution. – Wareinglet
instead ofvar
– Acclamation