发送电子邮件 - MFMailComposeResult

Mig*_*rri 10 switch-statement swift

我正在尝试将我的一个应用程序从Obj-C迁移到Swift,我遇到了电子邮件管理方面的问题.
我按小时搜索,但我没有找到如何解决这个问题.
基本上,我正在尝试迁移该func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!)功能.

问题是交换机内没有选项有效.

func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!)
{
    switch result.value
    {
        case CUnsignedInt(MFMailComposeResultCancelled):
            var alert = UIAlertController(
                title: NSLocalizedString("sendingStatus", tableName: "LocalizationFile", comment:"sendingStatus"),
                message: NSLocalizedString("emailCancelledByUser", tableName: "LocalizationFile", comment:"emailCancelledByUser"),
                preferredStyle: UIAlertControllerStyle.Alert)
            self.presentViewController(alert, animated: true, completion: nil)
        case MFMailComposeResult(MFMailComposeResultFailed):
            var alert = UIAlertController(
                title: NSLocalizedString("sendingStatus", tableName: "LocalizationFile", comment:"sendingStatus"),
                message: NSLocalizedString("emailSentFailed", tableName: "LocalizationFile", comment:"emailSentFailed"),
                preferredStyle: UIAlertControllerStyle.Alert)
            self.presentViewController(alert, animated: true, completion: nil)
        case MFMailComposeResultSaved:
            var alert = UIAlertController(
                title: NSLocalizedString("sendingStatus", tableName: "LocalizationFile", comment:"sendingStatus"),
                message: NSLocalizedString("emailSaved", tableName: "LocalizationFile", comment:"emailSaved"),
                preferredStyle: UIAlertControllerStyle.Alert)
            self.presentViewController(alert, animated: true, completion: nil)
        default:
            var alert = UIAlertController(
                title: NSLocalizedString("sendingStatus", tableName: "LocalizationFile", comment:"sendingStatus"),
                message: NSLocalizedString("emailNotSent", tableName: "LocalizationFile", comment:"emailNotSent"),
                preferredStyle: UIAlertControllerStyle.Alert)
            self.presentViewController(alert, animated: true, completion: nil)
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Cra*_*tis 20

不要忘记您还可以在特定结果类型上使用.rawValue(.value在较旧版本的Swift中),将变量结果与之比较:

    var result:MFMailComposeResult = MFMailComposeResultCancelled

    switch(result.value) { // <-- Here, note .value is being used
        case MFMailComposeResultCancelled.value: // <-- And here as well!
            print("Cancelled")
        default:
            print("Default")
    }
Run Code Online (Sandbox Code Playgroud)