How can I define a method that can be called from anywhere, in every viewcontroller class?
I have a method that brings me a json file, and i want it to be reusable, since i have several json calls on my app.
Can you help me?
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.
You can add it through a category:
EDIT
Create a new .h .m file pair and in the .h file:
Then in the .m file:
Where I’m just assuming that you’ll be returning an NSArray, you can put any method there and extend all UIViewControllers. The method bringJSON will be available to all UIViewControllers and its subclasses.