objective c - How do create a global method in iOS? -
I use a POST request for a URL, parsing JSON and doing many useful things, I am trying to do Unfortunately I need to use it multiple times in multiple view controllers, what would be the best way to do this?
I have found a working solution for variables (global variables used in each VC). Looks like .m file:
#import "DataClass.h" @ Implementation DataClash synthesis string; @ Synthesis credit; @ Synthesis point; @ Synthesis global name; @Synthesis questionsCount; @ Synthesis wrong questions; @check the exact question; Fixed dataclass * instance = zero; + (DataClass *) getInstance {@synchronized (self) {if (example == zero) {example = [dataclass new]; }} Return example; }
And every time I call the using a variable using the GetInstance method / modify the data class object. This method now receives some NSString parameters and also returns an NSString.
So my question is .. Can I use the same class to make my call poststral method global and available for every VC in my app? Should I use the dataclass or have a better solution?
You can use inline static method available everywhere.
For example, create a function like this and you can use it everywhere. In your implementation, you call it it like this: BOOL rep = myTestMethod (@ "foo", 1); Code>
Br <> Do not forget your header in the files to use your function.
Comments
Post a Comment