Question

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.

Was it helpful?

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;

OTHER TIPS

What does superglobal mean in this context?

It's just C... you can easily define a variable in one file, and access it from all over the place (just use something like extern int yourVariable; in those files).

I actually ended up using [(myAppDelegate *)[[UIApplication sharedApplication] delegate] myVariable] instead.

I found that to be a bit more simple than having to import the delegate and class in every file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top