Ios MFMailComposeViewControllerDelegate不符合协议NSObjectProtocol
我正在尝试使用我制作的Ios MFMailComposeViewControllerDelegate不符合协议NSObjectProtocol,ios,swift,Ios,Swift,我正在尝试使用我制作的MFMailComposeViewController从我的应用程序发送电子邮件: func sendMail() { if (MFMailComposeViewController.canSendMail()) { let mail = MFMailComposeViewController() mail.mailComposeDelegate = self mail.setToRec
MFMailComposeViewController
从我的应用程序发送电子邮件:
func sendMail() {
if (MFMailComposeViewController.canSendMail()) {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients([self.customerMail?.first ?? ""])
} else {
}
}
extension MyViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
}
}
因此,我必须添加协议MFMailComposeViewControllerDelegate
,我这样做:
func sendMail() {
if (MFMailComposeViewController.canSendMail()) {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients([self.customerMail?.first ?? ""])
} else {
}
}
extension MyViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
}
}
那么为什么编译器要我添加NSObjectProtocol
如果我看到MFMailComposeViewControllerDelegate
在他的协议中只有一个方法,那么为什么我要添加所有这些委托:
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?) {
}
}
扩展CustomerDetailPresenter:MFMailComposeViewControllerDelegate{
func isEqual(uObject:Any?)->Bool{
}
var散列:Int{
}
var超类:AnyClass{
}
func`self`()->self{
}
func perform(uaselector:Selector!)->非托管{
}
func-perform(uaselector:Selector!,带对象:Any!)->非托管{
}
func-perform(uaselector:Selector!,with-object1:Any!,with-object2:Any!)->非托管{
}
func isProxy()->Bool{
}
func isKind(属于aClass:AnyClass)->Bool{
}
func isMember(属于aClass:AnyClass)->Bool{
}
func符合(协议)->Bool{
}
func响应(对选择器:选择器!)->Bool{
}
变量说明:字符串{
}
func-mailcomosecontroller(u控制器:mfmailcomoseviewcontroller,didFinishWith结果:MFMailComposeResult,错误:error?){
}
}
怎么了?为什么我要添加所有这些我不需要使用的委托?如果我必须使用此委托,我应该在需要返回值的委托中插入什么?
感谢您无论您在哪里使用
MFMailComposeViewControllerDelegate
,您声明的符合MFMailComposeViewControllerDelegate
的类也需要符合NSObjectProtocol
您可以从NSObject继承来修复此问题
class CustomersDetailPresenter: NSObject
class MyViewController: UIViewController, NSObject
请共享
CustomerDetailPresenter
的代码