switch-statement – 发送电子邮件 – MFMailComposeResult

前端之家收集整理的这篇文章主要介绍了switch-statement – 发送电子邮件 – MFMailComposeResult前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试将我的一个应用程序从Obj-C迁移到 Swift,并且我有电子邮件管理的问题.
我在几小时内搜索,但是我没有找到如何解决这个问题.
基本上,我试图迁移func mailComposeController(控制器:MFMailComposeViewController !,didFinishWithResult结果:MFMailComposeResult,错误: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",comment:"emailCancelledByUser"),preferredStyle: UIAlertControllerStyle.Alert)
            self.presentViewController(alert,animated: true,completion: nil)
        case MFMailComposeResult(MFMailComposeResultFailed):
            var alert = UIAlertController(
                title: NSLocalizedString("sendingStatus",message: NSLocalizedString("emailSentFailed",comment:"emailSentFailed"),completion: nil)
        case MFMailComposeResultSaved:
            var alert = UIAlertController(
                title: NSLocalizedString("sendingStatus",message: NSLocalizedString("emailSaved",comment:"emailSaved"),completion: nil)
        default:
            var alert = UIAlertController(
                title: NSLocalizedString("sendingStatus",message: NSLocalizedString("emailNotSent",comment:"emailNotSent"),completion: nil)
    }
}
不要忘记您也可以使用.rawValue(.旧版本的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")
    }
原文链接:https://www.f2er.com/swift/318804.html

猜你在找的Swift相关文章