switch-statement – 发送电子邮件 – MFMailComposeResult
发布时间:2020-12-14 05:19:19 所属栏目:百科 来源:网络整理
导读:我正在尝试将我的一个应用程序从Obj-C迁移到 Swift,并且我有电子邮件管理的问题. 我在几小时内搜索,但是我没有找到如何解决这个问题. 基本上,我试图迁移func mailComposeController(控制器:MFMailComposeViewController !,didFinishWithResult结果:MFMailC
我正在尝试将我的一个应用程序从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") } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |