• 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: Marco S Hyman <email@hidden>
  • Date: Wed, 7 Oct 2009 10:47:08 -0700

On Oct 7, 2009, at 10:33 AM, Steve Christensen wrote:

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?

Yes, because you're modifying the value of that key every time.

No. Read the code snip again. setInteger will only be set when PIFirstRun is YES. When YES PIFirstRun is set to NO so future runs will skip setting myInteger. Unless, as you noted in comments I snipped, the preferences file is deleted or other code sets PIFirstRun back to YES.

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

Add it to the defaults dictionary:

NSDictionary* defaults = [NSDictionary dictionaryWithObjectsAndKeys:
				[NSNumber numberWithBool:YES], @"PIFirstRun",
				[NSNumber numberWithInt:5],    @"myInteger",
				nil];

[[NSUserDefaults standardUserDefaults] defaults];

That may also do the trick. I say MAY because it is possible that the act of setting the code might cause some side effect that won't occur if the defaults are initialized to the value.

/\/\arc

_______________________________________________

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


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

  • Prev by Date: Re: Constructive Criticism
  • Next by Date: Re: app delegate +initialize
  • 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