Friday, June 17, 2011

Objective C

Objective C is the programming language of the iPhone. It is similar to C but there are a lot of differences.
For example, a simple class in C would look like:
class classname : public superclassname
{
protected:
 // instance variables

public:
 // Class (static) functions
 static void * classMethod1();
 static return_type classMethod2();
 static return_type classMethod3(param1_type param1_varName);

 // Instance (member) functions
 return_type instanceMethod1(param1_type param1_varName, param2_type param2_varName);
 return_type instanceMethod2WithParameter(param1_type param1_varName, param2_type param2_varName=default);
};
In Objective C, It would be:

@interface classname : superclassname
{
   // instance variables
}
+ classMethod1;
+ (return_type)classMethod2;
+ (return_type)classMethod3:(param1_type)param1_varName;

- (return_type)instanceMethod1:(param1_type)param1_varName :(param2_type)param2_varName;
- (return_type)instanceMethod2WithParameter:(param1_type)param1_varName andOtherParameter:(param2_type)param2_varName;
@end

The , +, means it is a static class method
The, -, means it is an instance method.

In objective C, it is import, instead of include

I will include more...