• 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: earliest code that runs?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: earliest code that runs?


  • Subject: Re: earliest code that runs?
  • From: Matt Neuburg <email@hidden>
  • Date: Tue, 27 Jul 2004 19:03:45 -0700

On or about 7/27/04 6:27 PM, thus spake "b.bum" <email@hidden>:

> On Jul 27, 2004, at 6:08 PM, Matt Neuburg wrote:
>> What's the earliest code that runs as my app starts up? I ask because I ran
>> into a problem today where a widget's initWithFrame referred to the
>> standardUserDefaults, but it turned out that the standardUserDefaults had not
>> yet been initialized because my call to register the baseline defaults, in a
>> class's +initialize method, had not yet been executed. I guess I was assuming
>> that a class's +initialize method would be called before any instance's init
>> method, but no. (I thought that because an example in the docs seemed to
>> imply it.) So where can I put code such that I can count on it to be executed
>> earlier than any other code? Thx - m.
>
> If the view is in a document based app's document NIB, then
> applicationWillFinishLaunching: is a great location.
>
> Otherwise, stick it in main:
>
> main() {
> NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
> [[NSUserDefaults standardUserDefaults] registerDefaults: [NSDictionary
> dictionaryWithContentsOfFile: [[NSBundle mainBundle] bundleWithPath:
> @"MyRegistrationDefaults" ofType: @"plist"];
> [p release];
> .... nsapplicationmain() ...
> }

Just for the record, no, applicationWillFinishLaunching: was not early
enough! Surprising, eh? So the code went into main(). Thanks very much - m.

--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide! NOW SHIPPING...! (Finally.)
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: earliest code that runs?
      • From: James DiPalma <email@hidden>
References: 
 >Re: earliest code that runs? (From: "b.bum" <email@hidden>)

  • Prev by Date: Re: earliest code that runs?
  • Next by Date: Re: Using NSApplescript while keeping UI responsive
  • Previous by thread: Re: earliest code that runs?
  • Next by thread: Re: earliest code that runs?
  • Index(es):
    • Date
    • Thread