gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 05:34:04 27 4
gpt4 key购买 nike

我正在尝试将我的一个应用程序从 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)
}
}

enter image description here

最佳答案

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

    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")
}

关于switch-statement - 发送电子邮件 - MFMailComposeResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24125578/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com