Skip to content

Objective C (Xcode) HowTo

cdm2012 edited this page Jun 5, 2015 · 35 revisions

This MAC Guide describes how to create your first Objective-C application using the Xcode 6.1.1+ IDE. These IDEs were chosen based upon the support of current iOS devices running iOS 8.0 seen in screen shot below:

Current iOS devices running iOS 8.0

In this MAC Guide, you will be covering the following topics:

  • Download, Install and Open Xcode 6.1.1+
  • Open a new project and designate a name for it
  • Edit Source Code, then run new implementation

If you have Xcode 6.1.1+ already you can skip to section 2, where there is a supplementary video that shows how to use Xcode 6.1.1+ in action. The tutorial concludes with editing the Objective-C source code from section 2 and running with the new implementation.

1 Download, Install and Open an Xcode 6.1.1+ Version

1.1 Choose your version of Xcode

All versions of Xcode can be downloaded here. There are many other versions of Xcode available from Apple listed below (CTRL + Click to open all downloads in a new window or tab).

Download Xcode

If you are using Mavericks, you can use Xcode 6.1.1. If you are using Yosemite, you can use the lastest (as of 06/04/15) Xcode 6.3.2.

1.2 Install the dmg file

After downloading the dmg file, Install it by double clicking it

Install dmg containing Xcode

1.3 Execute the Xcode 6.1.1+ Application

Once you can execute the Xcode 6.1.1+ file, it will prompt you to to select a project.

Execute Xcode

1.4 Create an Xcode 6.1.1+ project

When selecting a project, keep in mind that it will hold all of your Objective-C projects.

Create project

2 Paste Objective-C project

2.1 How to paste and generate a Project

The image below is a video that provides an example of how to generate a Objective-C project. (CTRL + Click to open video in a new window or tab).

Lawn Mower Video

The source code from the video can be copied from section 2.2

2.2 Copy source code

Highlight the source code below and copy it (CTRL + C or Right Click)

   public class LawnMower {

       /**
        * The main method is the entry point to Objective-C programs.
        * @param args The arguments sent in from the command line
        */
       public static void main(String[] args) {
           System.out.println("This program creates a yard to a specific size...");

           // create (length, width & area) variables for the yard and house 
           double yardLength = 0.0, yardWidth = 0.0, yardArea = 0.0;
    
           // yardArea and houseArea calculations will be made here
           yardArea = (yardWidth * yardLength);
    
           // formatting for theses values will be output here
           System.out.println("\nThe area of the yard is " + yardArea);
       }
   }

See more on the main method at Oracle's Getting Started Guide.

2.3 Paste the source code

Paste the source code by right clicking in the Package Explorer and pasting the copied content.

Paste Source

2.4 First project created

Your project is now generated for you in the package explorer, with the following project structure.

First Project

2.5 Run the project

Now that you have a project, you can now run your application. To start the Objective-C Application, select your project by right click on it, Then select Run-As-> Objective-C Application . You should get the following result:

   This program creates a yard to a specific size...
   The area of the yard is 0.0

3 Create Objective-C project

3.1 Select Objective-C Project

Select File → New → Objective-C Project and create the Objective-C project "LawnCare". The follow the example below.

Create Project

3.2 Completed Project

After clicking "Finish", you will have the following project structure.

Completed Project

4 Rename (Refactor) Project

4.1 Find the project that is to be renamed

Right Click on the project's name. Then select Refactor → Rename

Refactor Project

4.2 Rename the Project

Enter the new name that you want your project to have.

Rename Project

5 Deleting a project

5.1 Select project to be deleted

Right Click on the project's name, then select Delete.

Select Project

5.2 Delete the project

There will be a prompt for deleting the project where you can delete it from the computer completely.

Delete Project

6 Import an existing project

6.1 Choose import option

Right Click in the Package Explorer, then select Import.

Select Package Explorer

6.2 Select import type

Choose the option to import an Existing Project into project.

Import Option

6.3 Choose the folder

Select the Browse button, then select the project folder that you want to import (e.g., LawnCare).

Choose Folder

6.4 Complete import with correct file path

You will then have the directory selected where your project is, now click Finish to bring in your project under its previous project settings.

Complete Import

7 Running the Application (As a Objective-C Programmer)

7.1 Edit the Source Code

Adding the following changes to the existing source code and you will get an output showing a Yard Area.

   double yardLength = 10.0, yardWidth = 10.0, yardArea = 0.0;

7.2 Run the Project

To start the Objective-C Application, select your project by right click on it, Then select Run-As-> Objective-C Application . You should get the following result:

   This program creates a yard to a specific size...
   The area of the yard is 100.0

Clone this wiki locally