【问题标题】:MFMailComposeResult constants don't compile in Swift 2.3MFMailComposeResult 常量不能在 Swift 2.3 中编译
【发布时间】:2016-11-08 16:36:27
【问题描述】:

我今天早上更新到 XCode 8 并选择将我的 Swift 文件转换为 2.3 而不是 3。我已经解决了我所有的编译问题,除了下面的代码。只有 MFMailComposeResultSent 案例实际上做了重要的事情。 XCode 说 MFMailComposeResultSent 和其他类似情况是未解析的标识符。最新的文档显示我应该使用 MFMailComposeResult.sent,并且自动建议功能提供了这种可能性,但它也拒绝编译。我将不胜感激有关如何使此编译器与 Swift 2.3 一起使用的信息。

谢谢。

func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError?) {
    switch result.rawValue {
    case MFMailComposeResultCancelled.rawValue:
        print("Mail canceled")
    case MFMailComposeResultSaved.rawValue:
        print("Mail saved")
    case MFMailComposeResultSent.rawValue:
        makeToast("Successfully sent email.", duration: 3)
        print("Mail sent")
    case MFMailComposeResultFailed.rawValue:
        print("Mail sent failure: \(error!.localizedDescription)")
    default:
        break
    }
    hideActivityIndicator()
    self.dismissViewControllerAnimated(true, completion: nil)
}

【问题讨论】:

    标签: swift email swift2.3


    【解决方案1】:

    rawValue 无处不在是怎么回事?只需打开外壳即可。像这样:

    switch result {
    case .Cancelled: // something
    case .Saved: // something
    // .. and so on
    

    【讨论】:

    • 谢谢。实际上,我使用文档显示的“.sent”和“.failed”进行了尝试,但我猜它不起作用,因为该文档适用于 Swift 3。您的方法解决了问题。
    • 嗯,当然这反过来又提出了一个问题,为什么你会选择使用过时的 Swift 版本。你让自己的事情变得更加困难。为什么?
    • 我将过渡到 3,但需要更缓慢地进行,因为以前的一些版本转换已经严重到要花费一整天的工作,而我目前负担不起。
    • 你正在经历像这个例子这样的事情是“少”的工作?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    相关资源
    最近更新 更多