This is an old revision of the document!
=====Methods==== “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 call from elsewhere in our code. Components to methods: -Declaration -Definition -Invocation ====Declaration==== **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: *- (RETURNTYPE) METHODNAME:(ARGUMENTTYPE*)ARGUEMENTNAME METHODNAME2:(ARGUMENTTYPE*)ARGUEMENTNAME2; 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==== **Definition**- writing the code that executes/is contained within the method. Known as the method body. Defining a Method Return Type: A method may return a value. The return_type is the data type of the value the function returns. Some methods perform the desired operations without returning a value. In this case, the return_type is the keyword void. Method Name: This is the actual name of the method. The method name and the parameter list together constitute the method signature. Arguments: A argument is like a placeholder. When a function is invoked, you pass a value to the argument. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the arguments of a method. Arguments are optional; that is, a method may contain no argument. Joining Argument: A joining argument is to make it easier to read and to make it clear while calling it. Method Body: The method body contains a collection of statements that define what the method does. Declaration Method declaration is required when you define a method in one source file and you call that method in another file. In such case you should declare the function at the top of the file calling the function.