What's the difference between a method and a selector?

前端 未结 3 774
悲哀的现实
悲哀的现实 2020-11-30 16:41

What the difference between a method, a selector and a message in Objective-C?

3条回答
  •  情深已故
    2020-11-30 17:25

    This site has a good overview of all the terminology in question: http://www.otierney.net/objective-c.html

    Check out the link, but I'll give a quick summary:

    A method is essentially like a method of function that you are used to in your favourite programming language.

    A message (from the article) "A message can be dynamically forwarded to another object. Calling a message on an object in Objective-C doesn't mean that the object implements that message, just that it knows how to respond to it somehow via directly implementing it or forwarding the message to an object that does know how to."

    Selectors can mean two things. It can refer to the name of a method, or "refers to the unique identifier that replaces the name when the source code is compiled. Compiled selectors are of type SEL." (from: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocSelectors.html)

提交回复
热议问题