You have 2 errors :
//
// ViewController.swift
// Diabell
//
// Created by Richard Klug on 14/04/2021.
//
import UIKit
import MessageUI
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func emailbButtonTapped( sender: Any) {
showMailComposer()
}
}
func showMailComposer() {
guard MFMailComposeViewController.canSendMail() else {
return
}
let composer = MFMailComposeViewController()
composer.mailComposeDelegate = self
composer.setToRecipients(["richard.klug@diabell.se"])
composer.setSubject("Diabell App Help")
composer.setMessageBody("Fyll i vad du behöver hjälp med", isHTML: false)
present(composer, animated: true)
}
need to conform to MFMailComposeViewControllerDelegate
class ViewController: UIViewController, MFMailComposeViewControllerDelegate {
Extra closing curly bracket line 21: remove it and put it line 34
Hence, the code after line 22 was out of the class, hence self not found and present does not apply to anything. So compiler tried to interpret as your own func.
Correct code:
class ViewController: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func emailbButtonTapped( sender: Any) {
showMailComposer()
}
func showMailComposer() {
guard MFMailComposeViewController.canSendMail() else{
return
}
let composer = MFMailComposeViewController()
composer.mailComposeDelegate = self
composer.setToRecipients(["richard.klug@diabell.se"])
composer.setSubject("Diabell App Help")
composer.setMessageBody("Fyll i vad du behöver hjälp med", isHTML: false)
present(composer, animated: true)
}
}
If that's OK, don't forget to mark the correct answer to close the thread.
Note: when you post code, please use the code formatter tool ().