On 29 Mar 2017, at 21:17, Jens Alfke <[email protected]> wrote:
> 
>> On Mar 29, 2017, at 10:52 AM, Quincey Morris 
>> <[email protected]> wrote:
>> 
>> If willFinishLaunching is not early enough, then you can put code in your 
>> “main” function, but I don’t know how feasible that is in Swift.
> 
> Another trick to run stuff earlier at launch is to add an -awakeFromNib 
> method to your app delegate, or any other object in your main nib. This can 
> be dangerous, though, because you can’t count on any other object in the nib 
> already being awoken, since the -awakeFromNib methods are called in random 
> order. (I once had a very hard to debug intermittent crash due to an ordering 
> dependency between two -awakeFromNib methods.)

It’s also important to note that your -awakeFromNib method may be invoked more 
than once, in particular if the object is the owner of a nib file, *and* it can 
sometimes be invoked at surprising moments (for instance, a recent auto layout 
problem in iDefrag turned out to be caused by the initial layout pass 
triggering -outlineView:viewForTableColumn:item:, which in turn caused a nib to 
load for the view, triggering an -awakeFromNib call *before the “normal” 
-awakeFromNib for the object in question* and worse, that -awakeFromNib was 
called *during layout*, and did things that triggered re-layout; the resulting 
layout glitch was quite hard to track down).  The upshot is that it isn’t 
necessarily even sufficient to ensure that your -awakeFromNib remembers whether 
you’ve initialised your object; you need to be very careful about what can 
trigger it and under what circumstance.

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to