Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Objective-C, how do you declare/use a global variable?

I have been researching this problem for a long time, and I can't seem to find the answer to this question. I am fairly new to iPhone programming, so sorry if this is a stupid question. If anyone has just specific code to post showing how this can be done, that will be very helpful.

like image 321
futurevilla216 Avatar asked Dec 17 '22 17:12

futurevilla216


2 Answers

Objective-C is a superset of C, so just do it the C way:

int globalX = 100;

And header file:

extern int globalX;
like image 198
D.C. Avatar answered Jan 08 '23 05:01

D.C.


You do it exactly the way you would in C. Here's a simple example:

int myGlobal = 3;
like image 27
Carl Norum Avatar answered Jan 08 '23 03:01

Carl Norum