How can I declare a global integer and use it across my app?
+2
A:
//SomeFile.h
extern int n;
//SomeFile.m
int n;
//SomeOtherFile.m
#import "SomeFile.h"
Now you can use global n in your SomeOtherFile.m file
Vladimir
2010-08-04 14:52:00
I have just tried this and it threw 12 errors concerning my variable. I tried CODE:://otherviewcontroller.hextern int lives;//otherviewcotroller.mlives = 5;and I also use it here in several times.//levelcleared.m#import "otherviewcontroller.h"score = lives * 1000; ::END OF CODE
Adam_D
2010-08-04 14:58:35
you didn't initialize correctly. use int lives = 5; in otherviewcontroller.m
Jesse Naugher
2010-08-04 15:00:13
tried that mate, it just throws a warning followed by the other 11 errors. Anybody else know what I'm doing wrong?
Adam_D
2010-08-04 15:04:20
What warnings and errors do you get?
Vladimir
2010-08-04 15:10:58
A:
You can store it as a property in your application delegate and access your application delegate everywhere using this singleton :
[[UIApplication sharedApplication] delegate]
Pierre Valade
2010-08-04 16:19:39