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 ancient bitter opposition to improved methods [of production] on the ancient theory that it more than temporarily deprives men of employment ... has no place in the gospel of American progress.”
—Herbert Hoover (18741964)