Theocacao
Leopard
Design Element
Comment on "Using Delayed Messages in Cocoa"
by Jon Hess — Sep 19
I cringe whenever I see -[NSObject performSelector:withObject:afterDelay:] In code. Especially when delay is non-zero.

The sample code doesn't finish initializing the objects until 1.0 second after load, at the bottom of the event loop. If anyone starts using your objects between then, you could be hosed.

In that 1 second, the user could close the window you just loaded.

A more correct solution would be to have one of your objects (probably file's owner) have connections to the rest, and have it, deterministically initialize them.

performSelector:afterDelay: may seem neat at first, until you realize all of the stuff that can happen between the performSelector:afterDelay: call and the actual selector invocation.
Back to "Using Delayed Messages in Cocoa"
Design Element

Copyright © Scott Stevenson 2004-2015