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 a Xcode 6.1.1+ IDE.

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

  • Download, Install and Open Xcode 6.1.1+ (on an Apple Operating System)
  • Create a project and designate a name for it
  • Paste Source Code into main.m and Run
  • Edit Source Code, then run new implementation

Xcode 6.1.1+ 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

If you have an Xcode that is 6.1.1+ already you can skip to section 2, where there is a supplementary video that shows how to use an Xcode that is 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 (CMD + 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

Then drag the .app file into the Applications folder.

Drag dmg to Applications

1.3 Execute the Xcode 6.1.1+ Application

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

Create a project

1.4 Create an Xcode 6.1.1+ project

When creating a project, keep in mind that it will hold all of your Objective-C source code.

Create Xcode 6.1.1+ project

In this case we're going to create a "Command Line Tools" project.

2 Update Objective-C source code

2.1 Copy source code

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

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        NSLog(@"This program creates a yard to a specific size...\n");
        
        // 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
        NSLog(@"The area of the yard is %f\n", yardArea);
    }
    return 0;
}

See more on the main method in the Mac Developer Library and the iOS Developer Library.

2.2 Paste the source code

Paste over the default source code by highlighting the source code inside of main.m, and pasting the copied content from above.

Paste Source

2.3 Run the source code

Now that you have a source code, you can now run your application. To start the Objective-C Application, select your source code 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 Running the Application (As an Objective-C Programmer)

3.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;

3.2 Run the source code

To start the Objective-C Application, select your source code 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