无法将 'MyClass' 类型的值分配给 'MFMailComposeViewControllerDelegate!' 类型的值

Cannot assign a value of type 'MyClass' to a value of type 'MFMailComposeViewControllerDelegate!'

我正尝试在 iOS 中通过以下方式发送电子邮件:

var picker = MFMailComposeViewController()
picker.mailComposeDelegate = self
picker.setSubject("Mic Data")

var messageBody = NSMutableString()

for var index = 0; index<array.count; index++ {
    messageBody.appendString(String(format: "%@\n", arguments: [array.objectAtIndex(index) as! String]))
}

picker.setMessageBody(messageBody as String, isHTML: false)

presentViewController(picker, animated: true, completion: nil)

但是我在行 picker.mailComposeDelegate = self 上遇到错误。但它应该工作。我以这种方式设置委托 class MainTableViewController: UITableViewController, MFMessageComposeViewControllerDelegate 并使用委托方法:

func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
    self.dismissViewControllerAnimated(true, completion: nil)
}

我做错了什么?

您将 MFMessageComposeViewControllerDelegate 添加到 class 而不是 MFMailComposeViewControllerDelegate。容易犯的错误。