I know there as various posts regarding global variables in SO, but nothing helped.
My problem is-
In my AppDelegate.h I declared two variables x and y. In my ClassA, I imported AppDelegate.h and added:
AppDelegate mainDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
and assigned values to mainDelegate.x and mainDelegate.y.
In ClassB, I assigned these x and y as
label1.text = mainDelegate.x;
label2.text = mainDelegate.y;
No errors,but it is null..nothing appears as label’s text.
Could anyone please help..
EDIT:
In AppDelegate.h:
@property (nonatomic, copy) NSString *x,*y;
In ClassA.m
mainDelegate.x=[[NSString alloc] initWithString:[homeArray objectAtIndex:indexPath.row]];
This mainDelegate.x I am trying to get from ClassB and it is null.
You should use
and not
By using copy, you are ensuring that the text labels stay consistent. While retain means that if you change the values of x and y somewhere, your text labels will also change.