So, I want to prefetch some of the data needed in the view controllers associated with the tab bar controller as the user moves from the login page to the home page (tab bar controller exists between these two view controllers). I’m fetching the data in a custom TabBarController class and using the following code to send it (doesn’t work):
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.destination is Profile { // Profile = one of the view controllers in the tab bar
let vc = segue.destination as? Profile
vc?.uid = self.userID
vc?.name = self.name
vc?.skills = self.skillSet
}
}
What is the best way to do this? Please note I can’t prefetch the data before the tab bar controller as that is the login page. If I prefetch the profile page data on the home page (tab bar controller {home, search, profile}), how can I transfer it to another view controller (to profile) in the same tab bar?
2
Answers
What is the best way to do this?
I believe once you perform login call (Inside login screen) you will have userID and other data related to that user, so inside Login controller you have added code for making Tabbar controller as initial controller.
So based on that best thing is to store userData into tabbar controller.
So once you sore data into tabbar controller (from either login or Home Screen) you can fetch user data in any root controller (home, search, profile) which is inside tab-bar by below code.
struct User { var userID: String? }
There are multiple ways you can achieve this.