I tried to implement MFMailComposeViewControllerDelegate to use mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?)
method but get the error:
Cannot declare conformance to 'NSObjectProtocol' in Swift; 'SettingsViewModel' should inherit 'NSObject' instead
What could be the problem?
Here is the code:
extension SettingsViewModel: MFMailComposeViewControllerDelegate {
public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true)
}
}
The
MFMailComposeViewControllerDelegate
protocol extends theNSObjectProtocol
protocol. You are only allowed to conform toNSObjectProtocol
by subclassing theNSObject
class.You need to find the declaration of
SettingsViewModel
in your source code and change it to extendNSObject
: