'How to change button action and title for user and guest user dynamically in swift

There are two users in my app one is guest user and other is logged in user. I have set button actions in home view controller as register and sign in if the user is not logged in. Now i want to change the button title and action in setting viewController to edit profile and log out if the user is logged in already.I have logout function in home viewController how can i access this function in setting viewController. Here is my code.

How i can perform action and change button userRegister to Edit Profile and sign in to logout out dynamically when user is already logged in.

HomeViewController.swift

func performlogOut(){ }

In setting viewController

@IBAction func userRegistration(_ sender: Any) {
    
    let storyBoard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyBoard.instantiateViewController(withIdentifier: "registerUser") as!  registerUser

    self.navigationController?.pushViewController(vc, animated: true)
    
}

  @IBAction func signIn(_ sender: Any) {
    
   
    let storyBoard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyBoard.instantiateViewController(withIdentifier: "SignInViewController") as!  SignInViewController
    self.navigationController?.pushViewController(vc, animated: true)
  
}


Solution 1:[1]

Create two buttons and hide one of them depending on the situation.

@IBOutlet weak var loginButton: UIButton!
@IBOutlet weak var editProfileButton: UIButton!

...

var isLoggedIn: Bool

...

loginButton.isHidden = isLoggedIn
editProfileButton.isHidden = !isLoggedIn

Software design-wise it's better to have two buttons because you separate the responsibilities.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 meaning-matters