A macro is more convenient, as it's defined only in one place.
But it will still create a new instance, every time it's used, as a macro is just text replacement for the pre-processor.
If you want to have a unique instance, you'll have to use FOUNDATION_EXPORT
(which means extern
).
In a public .h file, declares the following:
FOUNDATION_EXPORT UIColor * scarlet;
This will tell the compiler that the scarlet
variable (of type UIColor
) will exist at some point (when the program is linked).
So it will allow you to use it.
Then you need to create that variable, in a .m file.
You can't assign its value directly, as it's a runtime value, so just set it to nil:
UIColor * scarlet = nil;
And then, at some point in your program (maybe in your app's delegate), set its value:
scarlet = [ [ UIColor ... ] retain ];
Do not forget to retain it, as it's a global variable which needs to live during the entire life-time of the program.
This way, you have only one instance, accessible from everywhere.