• 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: Steve Christensen <email@hidden>
  • Date: Wed, 07 Oct 2009 11:40:25 -0700


On Oct 7, 2009, at 10:47 AM, Marco S Hyman wrote:

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.

My mistake.

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.

I suppose if something was bound to that key then some other behavior could be triggered. If the idea was that the value really should be initialized once then putting it in the defaults would be best, unless you wanted to know if the value had been set to some value vs. being undefined.


_______________________________________________

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>)
 >Re: [iPhone] Application running for the very first time... (From: Steve Christensen <email@hidden>)
 >Re: [iPhone] Application running for the very first time... (From: Marco S Hyman <email@hidden>)

  • Prev by Date: Re: EXC_BAD_ACCESS when -fobjc-gc is on (Was: Memory corruption ...)
  • Next by Date: Re: NSAlert - multiple key equivalents for buttons?
  • Previous by thread: Re: [iPhone] Application running for the very first time...
  • Next by thread: 10.6 specific crash
  • Index(es):
    • Date
    • Thread