• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [iPhone] Application running for the very first time...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [iPhone] Application running for the very first time...


  • Subject: Re: [iPhone] Application running for the very first time...
  • From: Ron Fleckner <email@hidden>
  • Date: Fri, 2 Oct 2009 16:15:03 +1000


On 02/10/2009, at 3:57 PM, James Lin wrote:


Thank you for the code snipet, but I am confused at the logic here...

the following code will be executed EVERY time the program runs, right?

NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithCapacity:10];
[dictionary setObject: [NSNumber numberWithBool:YES] forKey:@"PIFirstRun"];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
[dictionary release];

so [dictionary setObject: [NSNumber numberWithBool:YES] forKey:@"PIFirstRun"] will run EVERYTIME the program runs?
Wouldn't that set my PIFirstRun to YES every time the user launch my application?


In that case....

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PIFirstRun"] == YES){
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"PIFirstRun"];
//first run

[userDefaults setInteger:5 forKey:@"myIngeter"];
}


will reset my "myInteger" to 5 EVERY single time?


What if all i want is to set "myInteger" to 5 the very first time my application lunches and ONCE ONLY?


Sorry for the confusion...thanks for help again...

James


Hi James,

you use -registerDefaults with user defaults to describe your app's 'factory default' settings. So, when your user first starts your app, the factory defaults get set to YES for first run, but then immediately get set to NO. Next time the user starts up your app, the 'factory defaults' have been changed (by your program, as above) and are never written over UNLESS s/he deletes your app's preferences file in his/her library.


You should check out the User Defaults Programming Guide in your Xcode docs


HTH,
Ron
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: [iPhone] Application running for the very first time... (From: James Lin <email@hidden>)

  • Prev by Date: Re: [iPhone] Application running for the very first time...
  • Next by Date: Re: possible bug in webView big and small load sizes...
  • Previous by thread: Re: [iPhone] Application running for the very first time...
  • Next by thread: Re: [iPhone] Application running for the very first time...
  • Index(es):
    • Date
    • Thread