Build Instagram App: Part 1 (Swift 5) - 2022 - Xcode 11 - iOS Development
private func setTabBar() {
let vc1 = HomeViewController()
let nav1 = UINavigationController(rootViewController: vc1)
nav1.tabBarItem = UITabBarItem(title: nil, image: UIImage(systemName: "house")?.withTintColor(.black, renderingMode: .alwaysOriginal), selectedImage: UIImage(systemName: "house.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal))
let vc2 = ExploreViewController()
let nav2 = UINavigationController(rootViewController: vc2)
nav2.tabBarItem = UITabBarItem(title: nil, image: UIImage(systemName: "globe.desk")?.withTintColor(.black, renderingMode: .alwaysOriginal), selectedImage: UIImage(systemName: "globe.desk.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal))
let vc3 = CameraViewController()
let nav3 = UINavigationController(rootViewController: vc3)
nav3.tabBarItem = UITabBarItem(title: nil, image: UIImage(systemName: "plus.circle")?.withTintColor(.black, renderingMode: .alwaysOriginal), selectedImage: UIImage(systemName: "plus.circle.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal))
let vc4 = NotificationViewController()
let nav4 = UINavigationController(rootViewController: vc4)
nav4.tabBarItem = UITabBarItem(title: nil, image: UIImage(systemName: "bell")?.withTintColor(.black, renderingMode: .alwaysOriginal), selectedImage: UIImage(systemName: "bell.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal))
let vc5 = ProfileViewController()
let nav5 = UINavigationController(rootViewController: vc5)
nav5.tabBarItem = UITabBarItem(title: nil, image: UIImage(systemName: "person")?.withTintColor(.black, renderingMode: .alwaysOriginal), selectedImage: UIImage(systemName: "person.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal))
tabBar.backgroundColor = .white
setViewControllers([nav1, nav2, nav3, nav4, nav5], animated: true)
}
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: scene)
window.makeKeyAndVisible()
window.rootViewController = TabBarViewController()
self.window = window
}
강의에서 사용되는 기존의 컴플리션 핸들러 스타일이 아니라 MVVM 양식에 맞춰 컴바인을 사용해보자. 별도로 컬렉션 뷰 또는 테이블 뷰를 사용한다면 이전에 공부한 Diffable Data Source를 사용해보자.