I have an objective-c/xcode project with several header and implementation files. I’d like to declare a variable that I can read and change from any file associated with the project. I tried doing extern int val = 0; in a header, but that lead to a linker error.
Would appreciate any help, thanks.
For storing and accessing an
intin and iOS app, I recommend usingNSUserDefaults.You can set the value from anywhere in the application by
Then you can retrieve the value from anywhere in the application by
This also works great for
BOOL,float,NSStringandNSArray. Check out theNSUserDefaultsdocumentation for more details and examples.