Just to point you in the right direction:
Static: https://stackoverflow.com/a/1250088/267892
Issue Description:
- You want your ClassA to have a ClassB class variable.
- You are using Objective-C as programming language.
- Objective-C does not support class variables as C++ does.
One Alternative:
Simulate a class variable behavior using Objective-C features
Declare/Define an static variable within the classA.m so it will be only accessible for the classA methods (and everything you put
inside classA.m).
Overwrite the NSObject initialize class method to initialize just once the static variable with an instance of ClassB.
You will be wondering, why should I overwrite the NSObject initialize method. Apple documentation about this method has the
answer: "The runtime sends initialize to each class in a program
exactly one time just before the class, or any class that inherits
from it, is sent its first message from within the program. (Thus the
method may never be invoked if the class is not used.)".
Feel free to use the static variable within any ClassA class/instance method.
Self: https://stackoverflow.com/a/2386015/267892
Using self causes your class' "setter" for this variable to be called,
rather than changing the ivar directly.
self.mainViewController = aController;
is equivalent to:
[self setMainViewController:aController];
On the other hand:
mainViewController = aController;
just changes the mainViewController instance variable directly,
skipping over any additional code that might be built into
UIApplication's setMainViewController method, such as releasing old
objects, retaining new ones, updating internal variables and so on.