Py Obj C - Messages and Methods

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:

    Pictures are for entertainment, messages should be delivered by Western Union.
    Samuel Goldwyn (1882–1974)

    I think it is a wise course for laborers to unite to defend their interests.... I think the employer who declines to deal with organized labor and to recognize it as a proper element in the settlement of wage controversies is behind the times.... Of course, when organized labor permits itself to sympathize with violent methods or undue duress, it is not entitled to our sympathy.
    William Howard Taft (1857–1930)