-2

This is the code i used to get two date variables from AppDelegate. But the variables never contain anything they just seem to be blank. My question is am i doing something wrong with the code?

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];

NSTimeInterval secondsBetween = [appDelegate->enterForgroundDate timeIntervalSinceDate:appDelegate->enterBackgroundDate];
Popeye
  • 11,839
  • 9
  • 58
  • 91
user3254808
  • 33
  • 1
  • 7

1 Answers1

-2

Define your variables in your AppDelegate.h:

@property (nonatomic, strong) NSDate *enterForgroundDate;
@property (nonatomic, strong) NSDate *enterBackgroundDate;
@property (nonatomic) BOOL testBool;

Then you should be able to do this:

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSTimeInterval secondsBetween = [appDelegate.enterForgroundDate timeIntervalSinceDate:appDelegate.enterBackgroundDate];
NSLog(@"appDelegate: %i", appDelegate.testBool );

For more information about the dot-notation or arrow-notation see this link

Community
  • 1
  • 1
Roland Keesom
  • 8,180
  • 5
  • 45
  • 52
  • Ok so I've implemented this in exactly as you have but if i try and access BOOL variable in this way it just seams to set them to NO even if they are YES in the app delegate class. Any ideas? – user3254808 May 09 '14 at 16:47
  • I've updated my answer to include a BOOL. It should just work in the same way. Let me know if it works for you – Roland Keesom May 10 '14 at 08:55