Sleep Paralysis
Sleep Paralysis

Reputation: 469

Accessing variables different view controllers

Ive been reading a lot of links on how to pass variables from SO on how to do this including this link.

Accessing variables of another class in xcode

however, i have already imported the FirstViewController.h file in my SecondViewController.m file in my FirstViewController.h file I have a variable defined as .h @property (nonatomic,retain) int test; .m @synthesized test;

and in view did load SecondViewController.h i try to do

FirstViewContoller.test=10;

but the variable is not recognized.

Would like if anyone could help please

Upvotes: 0

Views: 207

Answers (1)

user529758
user529758

Reputation:

You can't set properties on classes. You can only set properties of objects, i. e. instances of a class. You have to write

FirstViewController *vc = [[FirstViewController alloc] init];
vc.test = 10;
// use then vc for whatever it should be used.

Oh, and by the way: this is not in any way related to Xcode.

Upvotes: 3

Related Questions