Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a great question.</p> <ul> <li><p><strong>Selector</strong> - a Selector is the <em>name</em> of a method. You're very familiar with these selectors: <code>alloc</code>, <code>init</code>, <code>release</code>, <code>dictionaryWithObjectsAndKeys:</code>, <code>setObject:forKey:</code>, etc. Note that the colon is part of the selector; it's how we identify that this method requires parameters. Also (though it's extremely rare), you can have selectors like this: <code>doFoo:::</code>. This is a method that takes three parameters, and you'd invoke it like <code>[someObject doFoo:arg1 :arg2 :arg3]</code>. There's no requirement that there be letters before each part of the selector components. As I said, this is extremely rare, and you will not find it used in the Cocoa frameworks. You can work with selectors directly in Cocoa. They have the type <code>SEL</code>: <code>SEL aSelector = @selector(doSomething:)</code> or <code>SEL aSelector = NSSelectorFromString(@"doSomething:");</code></p></li> <li><p><strong>Message</strong> - a message is a selector and the arguments you are sending with it. If I say <code>[dictionary setObject:obj forKey:key]</code>, then the "message" is the selector <code>setObject:forKey:</code> plus the arguments <code>obj</code> and <code>key</code>. Messages can be encapsulated in an <code>NSInvocation</code> object for later invocation. Messages are sent to a <em>receiver</em>. (ie, the object that "receives" the message).</p></li> <li><p><strong>Method</strong> - a method is a combination of a selector and an implementation (and accompanying metadata). The "implementation" is the actual block of code; it's a function pointer (an <code>IMP</code>). An actual method can be retrieved internally using a <code>Method</code> struct (retrievable from the runtime).</p></li> </ul> <hr> <p>Some other related things that you didn't ask for:</p> <ul> <li><p><strong>Method Signature</strong> - a method signature represents the data types returned by and accepted by a method. They can be represented at runtime via an <code>NSMethodSignature</code> and (in some cases) a raw <code>char*</code>.</p></li> <li><p><strong>Implementation</strong> - the actual executable code of a method. Its type at runtime is an <code>IMP</code>, and it's really just a function pointer. iOS 4.3 includes a new ability to turn a block into an <code>IMP</code>. This is <em>really cool</em>.</p></li> </ul> <p>One of the fun things to realize is that the <em>name</em> of a method (the selector) is distinct from the <em>implementation</em> of the method (the IMP). This means that you can swap them around, if you're feeling daring. You can also add and remove methods at runtime, because all you're doing is editing an entry in a hash table: the key is the selector, and the value is the <code>IMP</code> of the method. This allows you to do some really crazy and trippy stuff. It's not for the faint of heart. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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