I am a beginner in programming and in iOS development, I am trying to make an app that use Tab Bar Controller and it has 5 Tab bars.
I make a User
class that has email, uid, name, and other user data like their domicile etc as the properties. This class is initialized in the view controller of first tab bar in the tab bar controller (index:0), let say we call it HomeVC. the instance of the User
class is initialized using the data that comes from the server.
the instance of this User
class, will be used several time in my app. let say when the user creating a post in the PostVC that located in the bottom / last VC in the navigation stack of the third tab bar (index:2). and also when the user see their own profile in profileVC.
I think making request repeatedly to get user data in some place in my app is not a good practise, since currently I am using Firestore database, more read the database means it needs more cost. so I want just making one request to the server to get the user data and then use that user data for my entire app.
at this time I make a super global variable ( a variable that located outside the class), so I can access it in everywhere in my app. but I just read that using super global variable is a bad programming practise.
so what should I do? do I have to pass the user data by using prepareForSegue
? is there any better option to solve this problem?