MFMailComposeViewControllerDelegate:无法在Swift中声明与“NSObjectProtocol”的一致性

rmbxnbpk  于 5个月前  发布在  Swift
关注(0)|答案(1)|浏览(44)

我试图使用mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?)方法实现MFMailComposeViewControllerDelegate,但得到错误:

  • 无法声明与Swift中的“NSObjectProtocol”的一致性;“SettingsViewModel”应继承“NSObject”而不是“NSObjectProtocol”*

有什么问题吗??
代码如下:

extension SettingsViewModel: MFMailComposeViewControllerDelegate {
    public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
        controller.dismiss(animated: true)
    }
}

字符串

w7t8yxp5

w7t8yxp51#

The MFMailComposeViewControllerDelegate protocol扩展了the NSObjectProtocol protocol。您只能通过子类化NSObject来符合NSObjectProtocol
您需要在源代码中找到SettingsViewModel的声明,并将其更改为扩展NSObject

class SettingsViewModel: NSObject {
   ...

字符串

相关问题