|
import UIKit |
|
|
|
class SceneDelegate: UIResponder, UIWindowSceneDelegate { |
|
|
|
var window: UIWindow? |
|
|
|
|
|
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { |
|
|
|
guard let windowScene = (scene as? UIWindowScene) else { return } |
|
|
|
// init window with the frameSize of the windowScene bounds |
|
window = UIWindow(frame: windowScene.coordinateSpace.bounds) |
|
|
|
//assign windowScene to window |
|
window?.windowScene = windowScene |
|
|
|
//assign the root ViewController |
|
window?.rootViewController = createTabBar() |
|
|
|
// show the ViewController |
|
window?.makeKeyAndVisible() |
|
} |
|
|
|
|
|
/// Adds a Navigation controller for SearchViewController() |
|
func createSearchNavController() -> UINavigationController { |
|
let seachVC = SearchViewController() |
|
seachVC.title = "Search" |
|
seachVC.tabBarItem = UITabBarItem(tabBarSystemItem: .search, tag: 0) |
|
|
|
return UINavigationController(rootViewController: seachVC) |
|
} |
|
|
|
/// Adds a Navigation controller for FavoritesViewController() |
|
func createFavoritesNavController() -> UINavigationController { |
|
|
|
let favoritesVC = FavoritesViewController() |
|
favoritesVC.title = "Favorites" |
|
favoritesVC.tabBarItem = UITabBarItem(tabBarSystemItem: .favorites, tag: 1) |
|
|
|
let favNavController = UINavigationController(rootViewController: favoritesVC) |
|
return favNavController |
|
|
|
} |
|
|
|
/// Adds a TabBar controller & assigns the Navigation controllers to it |
|
func createTabBar() -> UITabBarController { |
|
let tabBar = UITabBarController() |
|
tabBar.viewControllers = [createSearchNavController(), createFavoritesNavController()] |
|
|
|
// adding tint color for TabBar |
|
UITabBar.appearance().tintColor = .systemTeal |
|
|
|
return tabBar |
|
} |