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:
“All the old supports going, gone, this man reaches out a hand to steady himself on a ledge of rough brick that is warm in the sun: his hand feeds him messages of solidity, but his mind messages of destruction, for this breathing substance, made of earth, will be a dance of atoms, he knows it, his intelligence tells him so: there will soon be war, he is in the middle of war, where he stands will be a waste, mounds of rubble, and this solid earthy substance will be a film of dust on ruins.”
—Doris Lessing (b. 1919)
“The comparison between Coleridge and Johnson is obvious in so far as each held sway chiefly by the power of his tongue. The difference between their methods is so marked that it is tempting, but also unnecessary, to judge one to be inferior to the other. Johnson was robust, combative, and concrete; Coleridge was the opposite. The contrast was perhaps in his mind when he said of Johnson: his bow-wow manner must have had a good deal to do with the effect produced.”
—Virginia Woolf (18821941)