I want to get data while the app is loading and use this in all the application. but how can I create a object and use it everywhere in my application ?
Thanks in advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The most common way I see is, to use the App Delegate. Perhaps, because it is the easiest way. However, the App Delegate is often abused. Some developers tend to give the App Delegate to much responsibility. Several times I have seen devs use the App Delegate as their data model. That would be considered bad design.
I say this simply as warning to not let this get out of hand. So here is one way to use an initialized object everywhere in your app:
object in App Delegate
When you need to reference the object somewhere in your applications as the App Delegate for it using your object’s getter method like this: