Interface And Implimentation

In Objective C, the file where the declaration of class is done is called the interface file and the file where the class is defined is called the implementation file.

A simple interface file MyClass.h would look like the following −

@interface MyClass:NSObject{ 
// class variable declared here
// class properties declared here
// class methods and instance methods declared here

The implementation file MyClass.m would be as follows −

@implementation MyClass
// class methods defined here

Object Creation

Object creation is done as follows −

MyClass  *objectName = [[MyClass alloc]init] ;


Method is declared in Objective C as follows −

-(returnType)methodName:(typeName) variable1 :(typeName)variable2;

An example is shown below.


You might be wondering what the andBreadth string is for; actually it’s an optional string, which helps us read and understand the method easily, especially at the time of calling. To call this method in the same class, we use the following statement −

[self calculateAreaForRectangleWithLength:30 andBreadth:20];

As said above, the use of andBreadth helps us understand that breadth is 20. Self is used to specify that it’s a class method.

Class Methods

Class methods can be accessed directly without creating objects for the class. They don’t have any variables and objects associated with it.



It can be accessed by using the class name (let’s assume the class name as MyClass)

Creating the First Application

Step 1 − Open Xcode and select Create a new Xcode project.

Step 2 − Select Single View Application.

Step 3 − Enter the product name, i.e., the name of the application, organization name, and then the company identifier.

Step 4 − Ensure that Use Automatic Reference Counting is selected in order to automatically release the resources allocated once it goes out of scope. Click Next.

Step 5 − Select the directory for the project and select create.

Step 6 − You will see a screen as follows −

Step 7 − Now, select iPhone simulator in the drop down near Run button and select run.

Step 8 − That’s it; you have successfully run your first application. You will get an output as follows −

Now let’s change the background color, just to have a start with the interface builder. Select Vie

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.