Well I have those 2 variables, an NSString and an NSMutable Array which is value I want to be global in all my tabs. So far I had only one (the NSString) and I could get its value normally. No that I tried having one more variable I get (null) value.
here is my code:
AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic,retain) NSString *myDate;
@property (nonatomic,copy) NSMutableArray *tracks_condition;
@end
and in the HomeView.m when i assign the values
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
parsed_date=[res objectForKey:@"date"];
NSLog(@"Date:%@",parsed_date);
delegate.myDate = parsed_date;
NSString *parsed_track=[res objectForKey:@"Data1"];
[delegate.tracks_condition addObject:parsed_track];
NSLog(@"Track 0 Static:%@",parsed_track);
NSLog(@"Track 0:%@",[delegate.tracks_condition objectAtIndex:0]);
parsed_date is being printed out normally and I can access it in aother tabs.
But I get:
Track 0 Static:0
Track 0: (null)
And i cannot understand why, as I add it as an object in the MutableArray. Of course i get (null) in every other tab.
Can you help me? i prefer by fixing that code and not suggesting something entirely different because I am not very experienced in IOS. Unless it is that easy.
Most likely this is because you are never instantiating a mutable array for your
tracks_conditionproperty. Just declaring a property on your AppDelegate class doesn’t create the object for you. You still need to alloc/init the object at some point before you can use it. Until then tracks_condition remains null, and any messages sent to it (such as attempting to add an object to the array) will be ignored.You can fix this by instantiating an object and setting the value of your property before using it. You could do this in your app delegate’s
application:didFinishLaunchingWithOptions: