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
MFMailComposeViewControllerDelegateprotocol extends theNSObjectProtocolprotocol. You are only allowed to conform toNSObjectProtocolby subclassing theNSObjectclass.You need to find the declaration of
SettingsViewModelin your source code and change it to extendNSObject: