Reputation: 2002
I'm trying to send an email from my app using MFMailComposeViewController
I made so:
func sendMail() {
if (MFMailComposeViewController.canSendMail()) {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients([self.customerMail?.first ?? ""])
} else {
}
}
so I've to add the protocol MFMailComposeViewControllerDelegate
and I made so:
extension MyViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
}
}
so why the compiler asked me to add NSObjectProtocol
if I look at Apple documentation I saw that MFMailComposeViewControllerDelegate
has only one method in his protocol, so why I should add all of these delegate:
extension CustomersDetailPresenter: MFMailComposeViewControllerDelegate {
func isEqual(_ object: Any?) -> Bool {
<#code#>
}
var hash: Int {
<#code#>
}
var superclass: AnyClass? {
<#code#>
}
func `self`() -> Self {
<#code#>
}
func perform(_ aSelector: Selector!) -> Unmanaged<AnyObject>! {
<#code#>
}
func perform(_ aSelector: Selector!, with object: Any!) -> Unmanaged<AnyObject>! {
<#code#>
}
func perform(_ aSelector: Selector!, with object1: Any!, with object2: Any!) -> Unmanaged<AnyObject>! {
<#code#>
}
func isProxy() -> Bool {
<#code#>
}
func isKind(of aClass: AnyClass) -> Bool {
<#code#>
}
func isMember(of aClass: AnyClass) -> Bool {
<#code#>
}
func conforms(to aProtocol: Protocol) -> Bool {
<#code#>
}
func responds(to aSelector: Selector!) -> Bool {
<#code#>
}
var description: String {
<#code#>
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
}
}
What's wrong? And why I should add all of these delegate that I don't need to use? If I've to use this delegate what I should insert in the delegates who need a return value? Thank you
Upvotes: 1
Views: 261
Reputation: 19750
Where ever you use MFMailComposeViewControllerDelegate
, The class your stating conforms to MFMailComposeViewControllerDelegate
also needs to conform to NSObjectProtocol.
You can just inherit from NSObject to fix this.
class CustomersDetailPresenter: NSObject
class MyViewController: UIViewController, NSObject
Upvotes: 2