• 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: James DiPalma <email@hidden>
  • Date: Wed, 28 Jul 2004 00:33:14 -0700

On Jul 27, 2004, at 7:03 PM, Matt Neuburg wrote:
Just for the record, no, applicationWillFinishLaunching: was not early
enough! Surprising, eh? So the code went into main(). Thanks very much - m.

As an alternative, you can use a subclass of NSApplication and put your defaults loading code into init. An application's delegate could also be used to register application defaults.

On Jul 27, 2004, at 6:08 PM, Matt Neuburg wrote:
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.)

As mmalc points out, for a given class, +initialize should get called before any method on that class or its instances gets called. No?

Anyway, if your view class wants to register some defaults, +initialize should work fine. If these defaults you want to register are specific to your view and not general to your application, it may not make sense to register them in main or in your application's -init method.

So where can I put code such that I can count on it to be executed
earlier than any other code?

+load also works, but you should be careful and read about how +load works. Also, Zero Link doesn't work so well if your app relies on +load methods getting called. Your specific problem of registering defaults doesn't seem like it should be solved by +load (even though it would work).

On Jul 27, 2004, at 6:42 PM, Shawn Erickson wrote:
You usually defer such stuff until awakeFromNib or applicationDidFinishLaunching: time, etc.

Why? Matt is asking about when to register defaults which need to be registered before they are read. You seem to be talking about when defaults are usually read; maybe?

On Jul 27, 2004, at 6:58 PM, Shawn Erickson wrote:
Also a view doesn't normally access user preferences itself but instead a controller does and configures the view as needed (or use binding to do this).

It is OK for views to access defaults directly it depends on why. Think about how NSTableViews, NSOutlineViews, and NSWindows (not a view, but still a ui without a controller nor a binding) use their autosave name in their IB preference panes. As developers, it is easier to take advantage of these features by entering an autosave name than by instantiating an NSUserDefaultsController or by instantiating a controller.



-jim
_______________________________________________
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: Glenn Andreas <email@hidden>
References: 
 >Re: earliest code that runs? (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: windowDidLoad
  • Next by Date: Re: WebKit BaseURL problems
  • Previous by thread: Re: earliest code that runs?
  • Next by thread: Re: earliest code that runs?
  • Index(es):
    • Date
    • Thread