Messages and Methods
In Objective-C, objects communicate with each other by sending messages, which is analogous to method calls in other object-oriented languages. When an object receives a message, it looks up the message's name, or selector, and matches it up with a method designated the same selector, which it then invokes.
The syntax for these message expressions is inherited from Smalltalk, and appears as an object, called the receiver, placed to the left of the name of the message, or selector, and both are enclosed within a pair of square brackets (the square bracket syntax is not inherited from Smalltalk). Colons within a selector indicate that it accepts one or more arguments, one for each colon. Intended to improve code readability, colons are placed within the selector such that when the required arguments are in place, the expression's intent is unambiguous:
;This is distinct from the syntax used in Python, and in many other languages, where an equivalent expression would read:
myLittleDuck.makeSomeNoise_eyesClosed_onOneFoot_(quack, True, True)Translating Objective-C selectors to Python method names is accomplished by replacing each colon with a single underscore and listing the arguments within a pair of parentheses at the end, as demonstrated above.
Read more about this topic: Py Obj C
Famous quotes containing the words messages and/or methods:
“Acknowledging separation feelings directly and sympathetically is the best way of coping with them. It is actually helpful to tell a toddler Ill miss you, or I will think of you during the day, or It is hard to say goodbye, or I cant wait to see you at the end of the day. These messages tell the child that he is important to the parent even when they are not together and that out of sight need not mean out of mind.”
—Alicia F. Lieberman (20th century)
“If men got pregnant, there would be safe, reliable methods of birth control. Theyd be inexpensive, too.”
—Anna Quindlen (b. 1952)