I believe I've followed the steps of other SO threads to invoke an action, via another method, when the UIBarButtonItem is tapped however I keep getting the following error Argument of '#selector' does not refer to an '@objc' method, property, or initializer
and the error is highlighting the #selector
text.
This is setting up the button:
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "\(barButtonItemText)", style: .done, target: self, action: #selector(inviteMethod(inviteMethod: inviteMethodSelected!)))
This is the method I'm trying to run when the button is tapped:
func inviteMethod (inviteMethod:String) {
let inviteMethod = inviteMethod
if inviteMethod == "email" {
inviteViaEmail(invitedContacts: self.invitedContacts)
}
else {
inviteViaText(invitedContacts: self.invitedContacts)
} }
Example of one of the invite methods in case it's helpful
func inviteViaEmail (invitedContacts:[Contact]) {
var invitedContactsEmails:[String] = []
for contactEmails in invitedContacts {
let emailAddress = contactEmails.emailAddress ?? ""
invitedContactsEmails.append(emailAddress)
}
let mc = MFMailComposeViewController()
mc.mailComposeDelegate = self as? MFMailComposeViewControllerDelegate
mc.setToRecipients(invitedContactsEmails)
mc.setSubject("Invite for Gallery App, Event \(event?.eventName)")
mc.setMessageBody("This is a test invite email \n\n\(event?.eventHost) has invited you to join their event", isHTML: false)
self.present(mc, animated: true, completion: nil)
}