“Method”, “message”, and “function” all (sort of) refer to the same thing in Objective-C.
A method is a section of code that we can execute (call) from elsewhere in our code.
Components to methods:
Declaration- the act of informing other objects about a function's name, return type, and parameters.
Declarations for public methods are included in the header files of Objective-C objects.
Declarations for private methods are included in the Definition and do not need additional code. These methods can only be called within a class.
Declarations take the form:
A dash at the start indicates a instance method. Can only be called on an instantiated object. When creating a method, always use a dash unless you have some overriding reason.
A plus sign at the start indicates a class method. Can only be called on the class itself, commonly used as custom initialization method.
Definition- writing the code that executes/is contained within the method. Known as the method body.
Methods are defined in implementation files, or .m files. The form is the same as the declaration, except with curly braces instead of a semicolon which contain the method body.
Invocation- the act of running the code contained within a method. A method is invoked on a target, where the target is the object that owns the method.
Consists of two parts
Invoking a method takes the form:
and can be nested infinitely deep:
[[[TARGET NAME] NAME2] NAME3];
where NAME2 and NAME3 are methods called on the objects returned by methods NAME and NAME2, respectively.