0

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.

cwiggo
  • 2,345
  • 8
  • 38
  • 82
  • Possible duplicate - [link](http://stackoverflow.com/questions/7081245/global-variables-in-xcode?rq=1) – Bamsworld Mar 12 '15 at 10:06
  • 1
    possible duplicate of [Constants in Objective-C](http://stackoverflow.com/questions/538996/constants-in-objective-c) – Shamas S Sep 12 '15 at 09:41

3 Answers3

2

declare a variable in any .h file (outside the @interface)

and import the .h file in the class you wanted to use.

riyaz
  • 1,073
  • 1
  • 7
  • 20
1

Please see this answer.

This isn't a very straightforward way, but it is the right way.

https://stackoverflow.com/a/539191/1891327

Community
  • 1
  • 1
Shamas S
  • 7,237
  • 8
  • 44
  • 58
0

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)

LoVo
  • 1,535
  • 14
  • 19