selector是方法名,message包括selector和方法的参数,method包括selector和方法的具体实现。
以下转自stackoverflow: http://stackoverflow.com/questions/5608476/whats-the-difference-between-a-method-and-a-selector
-
Selector - a Selector is the name of a method. You're very familiar with these selectors:
alloc
,init
,release
,dictionaryWithObjectsAndKeys:
,setObject:forKey:
, 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:doFoo:::
. This is a method that takes three parameters, and you'd invoke it like[someObject doFoo:arg1 :arg2 :arg3]
. 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 typeSEL
:SEL aSelector = @selector(doSomething:)
orSEL aSelector = NSSelectorFromString(@"doSomething:");
-
Message - a message is a selector and the arguments you are sending with it. If I say
[dictionary setObject:obj forKey:key]
, then the "message" is the selectorsetObject:forKey:
plus the argumentsobj
andkey
. Messages can be encapsulated in anNSInvocation
object for later invocation. Messages are sent to a receiver. (ie, the object that "receives" the message). -
Method - 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
IMP
). An actual method can be retrieved internally using aMethod
struct (retrievable from the runtime).