Smart Refactoring Patterns
AppStore JSON APIs
In this lesson, we'll go ahead and perform some code refactoring that allows us to more easily introduce screens in our BaseTabBarController class. Doing so will greatly reduce the amount of logic and code that is repeated, which is almost always a welcomed improvement. At the end of this lesson, we'll also introduce our AppsSearchController list view. Enjoy.

Comments (8)
richardbranson
4 years ago
This was an amazing lesson. And that UICollectionViewFlowLayout() trick was great. Now my BaseTabBarController file looks clean and consistent. Thanks!
dneckles
4 years ago
Yeah that trick in the last minute was incredible. Swift is something else.
ezechinwa
4 years ago
Hi b, I am so happy with the little have done so far without using storyboards. purchasing this course is the best investment I have ever made :)
Brian Voong
4 years ago
fkeebie
4 years ago
I have just finished your fantastic course of Instagram Firebase up to Lesson 43 and purchased this another fabulous course. I think I can further deepen skill and knowledge on iOS app development. As I turned 70 years old last year, I need repeated learning to make my knowledge firm. Thanks to your courses including free ones I could make simple chat app and instagram-like app and am now enjoying casual connectivity with my granddaughter (6 years old) . Many thanks.
Allister Smith
4 years ago
I thought I was the only oldie! I'm 67.
fef
4 years ago
hi Brian thx for all trick and tips on your lesson, we learn soo much . I wanna ask you a question, about POP on smart refactoring. The same function used to smart refactoring, we can put it on a protocol and conform our tabBar to it, it's a good alternative solution using POP like that ? protocol generateControllers {} extension generateControllers { func creatController(with title: String, image: UIImage) -> UINavigationController { let controller = UIViewController() controller.view.backgroundColor = .white controller.navigationItem.title = title let navController = UINavigationController(rootViewController: controller) navController.tabBarItem.title = title navController.tabBarItem.image = image navController.navigationBar.prefersLargeTitles = true return navController } } thx you.
Brian Voong
4 years ago
Tokyojogo
4 years ago
Hi Brian, What about moving the createNavController func into a separate helper file? Would you suggest doing something like that to keep the VC leaner? Thanks.
Brian Voong
4 years ago
Stefan Milinkovic
4 years ago
Hi Brian one question for you, In the createNavController func , you have entered UIViewController as a return parameter Why does navController pass as a UIViewController (When I did UINavigationController as a return parameter it had the same result) Tnx :o
Amir Alagic
4 years ago
It is because UINavigationController inherits from UIViewController and it can be casted to its parent class (UIViewController). You can search and read more this if you search for object oriented programming and polymorphism.
Lazaro Ambrosio
3 years ago
Hello, I have a question I followed along and my issue is that the border of the tab bar is shown bottom. But it does not show the top of the phone. The style of the bar is there at the bottom. But when Today is shown it shows without the border. The code is below. import UIKit class BaseTabBarController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() viewControllers = [ createNavController(viewController: UIViewController(), title: "Today", imageName: "today_icon"), createNavController(viewController: UIViewController(), title: "Apps", imageName:"apps" ),createNavController(viewController: UIViewController(), title: "Search", imageName: "search"), ] } fileprivate func createNavController(viewController:UIViewController,title: String, imageName:String) -> UIViewController { let navController = UINavigationController(rootViewController: viewController) viewController.navigationItem.title = title viewController.view.backgroundColor = .white navController.tabBarItem.title = title navController.navigationBar.prefersLargeTitles = true navController.tabBarItem.image = UIImage(named: imageName) return navController } } Here is my scene delegate : Am I missing something? Best and thank you! 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 } window = UIWindow(frame: windowScene.coordinateSpace.bounds) window?.windowScene = windowScene window?.rootViewController = BaseTabBarController() window?.makeKeyAndVisible() }
Lazaro Ambrosio
3 years ago
To clarify my problem is that the tab bar border color on top does not show. While the bottom does show white. I do not know the reason this is happening.
Brian Voong
3 years ago
Lazaro Ambrosio
3 years ago
https://docs.google.com/document/d/13EzBp_uc3ITkeWkhmT6-jMdPXV1wOEX3RWgxWf5jB64/edit?usp=sharing
Brian Voong
3 years ago
Lazaro Ambrosio
3 years ago
I did not know that. Thanks that explains why it was not showing ! I got it to work thank you for your time!
agvg24
3 years ago
Hi, Nice video. Tabbar is commonly working fine. But, I want implement like confirmation alert for moving one screen to another. Example: click tab1:- show alert "Do you want navigate tab2?" if "YES" : navigate to tab 2 if "NO" : no changes same screen It is like logout confirmation. What is the way to implement?. can you please explain?
Brian Voong
3 years ago
jdhindsa
2 years ago
I'm confused (15:41 mark of the video). Why can't we just initialize the collectionViewLayout in the viewDidLoad() method, like this: collectionView.collectionViewLayout = UICollectionViewFlowLayout() Why do we have to do it with a call to super.init() in the default initializer?
HELP & SUPPORT