Search code examples
iphoneobjective-ciossuperglobals

Superglobals in Objective-C and iOS


I'm trying to add some sort of a superglobal in my app. It will only store a small integer, but I need it to be accessible from anywhere in my app.

I know you can use the delegate for this, but wouldn't it be easier if you could just set a superglobal in your application (of course it has to be alterable)?

So, what is the best way to create a superglobal in your iOS application?

Oh, and I should probably mention I want my App Delegate to "own" the variable.


Solution

  • define a global variable in some implementation (.m) file:

    int superGlobal;
    

    then you can access it in any other file declaring it there:

    //SomeOtherFile.m;
    extern int superGlobal;