Skip to content

Instantly share code, notes, and snippets.

@dbaldwin
Created July 24, 2012 14:53
Show Gist options
  • Save dbaldwin/3170422 to your computer and use it in GitHub Desktop.
Save dbaldwin/3170422 to your computer and use it in GitHub Desktop.
iOS gist for doing something only the first time an app is run
- (void)viewDidLoad
{
[super viewDidLoad];
// Get a reference to the user defaults database
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// If this is the first run we're going into this if statement
if(![defaults objectForKey:@"firstRun"])
{
NSLog(@"This is the first run!!!!");
// Set this and use later to determine what to do on first run
isFirstRun = TRUE;
// Persist the first run var so the next time we don't enter this if statement
[defaults setObject:[NSDate date] forKey:@"firstRun"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment