Binary operator '==' cannot be applied error


I have gotten stumped on this one, I am working with segue's and received the message below while trying to use the "==" operator for the if else. The error message is
Binary operator '==' cannot be applied to operands of type 'UIButton' and '(Any) -> ()'

I have also included the code written so far on this. I understand it does not like the operator to be used to compare the UIButton but not clear on how to fix it. Thank You

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var Username: UITextField!

@IBAction func forgotUsername(_ sender: Any) {
    performSegue(withIdentifier:"forgotUsername" , sender:forgotUsername)

@IBAction func forgotPassword(_ sender: Any) {
    performSegue(withIdentifier: "forgotPassword", sender: forgotPassword)
override func viewDidLoad() {
    // Do any additional setup after loading the view, typically from a nib.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let sender = sender as? UIButton else {
    if sender == forgotUsername {
        segue.destination.navigationItem.title = "ForgotUsernameButton"
    } else if sender == forgotPassword {
        segue.destination.navigationItem.title = "ForgotPasswordButton"
    } else {
        segue.destination.navigationItem.title = Username.text


forgotUsername and forgotPassword are functions, not buttons.

You probably meant to reference outlets? If you didn't declare these already:

@IBOutlet weak var forgotUsername: UIButton!
@IBOutlet weak var forgotPassword: UIButton!

Also, as a side node, use camelCase for variables, so username instead of Username

Thank you so much, that cleared the error, I totally missed that. I am fairly new to Swift but really love working with it.

Terms of Service

Privacy Policy

Cookie Policy