Messages are enclosed by square brackets and are formatted:
The reciever of the message must be of type Class(a class) or id(an object).
Example:
Arguments
A message can have any number of arguments. Arguments are seperated by colons and each argument may have a name associated with it.
Examples:
Message with single argument:
Message with two arguments:
Argument names are optional:
You can even do things like:
Messages within Messages
Just as C functions can be used as arguments in other C functions,
messages and expressions can also be placed within messages.
For example:
Another example:
Selectors
Selectors are the run-time system's identifier for a method. The SEL data type is used for selectors.
The sel_get_uid() function can be used to get a method's selector from it's name:
The - perform: method is used to send a message to an object using a selector.
is the same as:
Arguments can also be sent:
is the same as:
Selectors are usefull for changing which message is sent to an object at runtime:
Or:
This is especially usefull for sending messages to a list of objects: