12.5.1. Building the Right Bar Button(s) for Sign In and Logout

//
// RightBarButtonManager.swift
// App12
//
// Created by Sakib Miazi on 6/2/23.
//
import UIKit
import FirebaseAuth
extension ViewController{
func setupRightBarButton(isLoggedin: Bool){
if isLoggedin{
//MARK: user is logged in...
let barIcon = UIBarButtonItem(
image: UIImage(systemName: "rectangle.portrait.and.arrow.forward"),
style: .plain,
target: self,
action: #selector(onLogOutBarButtonTapped)
)
let barText = UIBarButtonItem(
title: "Logout",
style: .plain,
target: self,
action: #selector(onLogOutBarButtonTapped)
)
navigationItem.rightBarButtonItems = [barIcon, barText]
}else{
//MARK: not logged in...
let barIcon = UIBarButtonItem(
image: UIImage(systemName: "person.fill.questionmark"),
style: .plain,
target: self,
action: #selector(onSignInBarButtonTapped)
)
let barText = UIBarButtonItem(
title: "Sign in",
style: .plain,
target: self,
action: #selector(onSignInBarButtonTapped)
)
navigationItem.rightBarButtonItems = [barIcon, barText]
}
}
@objc func onSignInBarButtonTapped(){
}
@objc func onLogOutBarButtonTapped(){
}
}setupRightBarButton(isLoggedin: Bool)
onSignInBarButtonTapped()
onLogOutBarButtonTapped()
In the above code, we use a different alert controller style, ".actionSheet". An action sheet pops up from the bottom edge.
Patching ViewController to display the Right Bar Buttons

Previous12.5. Implementing Register and Sign InNext12.5.2. Register Screen: Create a user in Firebase
Last updated