0

var token : String { get and set} Can any tell how to use the same thing in Objective C. In swift I can use any where in the project to access the token. I want the same thing to be done..

Willeke
  • 14,578
  • 4
  • 19
  • 47
sunil
  • 70
  • 8
  • 1
    Possible duplicate of [How to use global variables in Objective-C?](http://stackoverflow.com/questions/3368877/how-to-use-global-variables-in-objective-c) – Willeke Mar 31 '17 at 08:50

1 Answers1

2

First, you should avoid to use global var with OOP.

If you really need to use global var, make it become an instance var in appdelegate.

If you don't want to put it in appdelegate, create a source file and declare as static var could solve it, remember access it by accessor, Never access global var directly.

GlobalVar.h

void setGlobalVar(int var);
int getGlobalVar(void);

GlobalVar.m

static int s_globalVar = 0;
void setGlobalVar(int var) {
    s_globalVar = var;
}

int getGlobalVar(void) {
    return s_globalVar;
}
John Henry
  • 46
  • 3