Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, that's what gets called. (After the delay, of course.) </p> <p><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/performSelector:withObject:afterDelay:" rel="nofollow noreferrer">The documentation</a> doesn't really explain what it means to "perform the selector", but what it means is exactly what you suspect.</p> <p>There is one small difference between using <code>performSelector:withObject:</code> type methods and sending the message directly: they only work if the object is actually an object (that is, an <code>id</code>, a pointer to an Objective C object). But <code>window</code> obviously is an object.</p> <p>(Strictly speaking, this isn't quite true. If you pass something that's the same size as an <code>id</code> or smaller, it will often work. In some cases it won't. In some cases it will work, but is illegal. In some cases, it will work and is legal but Apple strongly recommends against it. There are no cases where it's a good idea—so instead of learning the specific rules, just assume it never works. The only reason to bring this up is that this used to be common practice in Objective C back in the NeXT days, so you may occasionally still see it in other people's today.)</p> <p>For more information about the <code>performSelector:</code> family, see the <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html" rel="nofollow noreferrer">NSObject Protocol Reference</a>, and the SO question <a href="https://stackoverflow.com/questions/1493125/using-performselector-vs-just-calling-the-method">Using -performSelector: vs. just calling the method</a>. (For information specifically about the <code>afterDelay:</code> variants, see the documentation linked above.)</p> <p>From the later edit to the question:</p> <blockquote> <p>the problem I'm having is that the method <code>showInWindow</code> get called after the delay but behaves like <code>[self showInWindow:nil]</code>. Any suggestion?</p> </blockquote> <p>First, in what way does it "behave like" the parameter is nil? Is the parameter actually nil? (Just log it in the <code>showInWindow:</code> implementation; if you haven't overridden the base implementation, just add an override that logs and calls the base.)</p> <p>Second, if it actually is nil, was it nil at the time you sent <code>performSelector:withObject:afterDelay:</code>? If so, obviously it'll still be nil when the selector is sent. Also, make sure <code>window</code> really is an <code>id</code> rather than some other type. (Note that if you've got members, properties, globals, and/or locals sharing the name <code>window</code>, it can be confusing which one you're referring to. This is a common source of problems.)</p> <p>If it's actually not nil when you schedule it, but is nil when it arrives, there are a few ways that could happen, but they're all less likely, and trickier to debug, than these two cases, so let's rule them out first.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload