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:
“The first of the undecoded messages read: Popeye sits in thunder,
Unthought of. From that shoebox of an apartment,
From livid curtains hue, a tangram emerges: a country.”
—John Ashbery (b. 1927)
“With a generous endowment of motherhood provided by legislation, with all laws against voluntary motherhood and education in its methods repealed, with the feminist ideal of education accepted in home and school, and with all special barriers removed in every field of human activity, there is no reason why woman should not become almost a human thing. It will be time enough then to consider whether she has a soul.”
—Crystal Eastman (18811928)