Files
Woka_Native_iOS/WOKA/Helpers/PopViewControllerGeneric.swift

23 lines
626 B
Swift
Raw Permalink Normal View History

//
// PopViewControllerGeneric.swift
// WOKA
//
// Created by MacBook Pro on 20/08/24.
//
import UIKit
/*
this helps in navigation back or pop the viewcontroller as generic type
*/
extension UINavigationController {
func getViewController<T: UIViewController>(of type: T.Type) -> UIViewController? {
return self.viewControllers.first(where: { $0 is T })
}
func popToViewController<T: UIViewController>(of type: T.Type, animated: Bool) {
guard let viewController = self.getViewController(of: type) else { return }
self.popToViewController(viewController, animated: animated)
}
}