I have just started to create my first iOs application with xcode.
How can I initialise and access a variable from anywhere in the application?
For example. I want to pass a BASE url 'http://www.repetitiveurl.com'. to many of my added classes.
I have just started to create my first iOs application with xcode.
How can I initialise and access a variable from anywhere in the application?
For example. I want to pass a BASE url 'http://www.repetitiveurl.com'. to many of my added classes.
declare a variable in any .h file (outside the @interface)
and import the .h file in the class you wanted to use.
Please see this answer.
This isn't a very straightforward way, but it is the right way.
Both given answers are correct, i just add my answer to give another option to solve your "problem":
You could declare the variable in the AppDelegate.h
, it depends on the variable and the use cases if this is a good idea. (usually it is not, but for some cases it is ok)