Xcode (Mac)

The Objective-C Programming Language

Introduction on how to install the Xcode IDE on a mac and create “Hello World” for the iPhone.

Xcode is located inside the App Store on a mac. Launch the App Store and search for Xcode:

Click Install (update if already installed):

The application will start downloading; it is a large 2gb+ program so it does take a little time, followed by installation. You can view the download and installation process by going to the created Developer folder created in the applications launch view:

Once installed launch Xcode:

Click on Create a new Xcode Project; for this Hello World iOS project we will just choose iOS ->Application->Single View Application

Choose a Project Name and fill out any additional company/org info:

This is the default view that comes up for our Single View Application. Xcode creates some skeleton code for us that launches and loads our application. This view also helps create your application icon, launch screen images, and gives rotation control.

Click play (upper left) to run the iPhone simulator and see what the program does so far. You will get an iPhone pop-up with a white screen:

Click on the MainStoryboard; this will show the white screen we looked at in the simulator.

On the right pane, you will see a long list of objects to add to the Storyboard. For our program we will add a label and a button that both say “Hello World”.

First click and drag Label onto the storyboard:

You will see in the right pane the preferences of this Label we just added. You can click on Text and change the text of our label to “Hello World”:

You can then find Button in the list and click and drag that onto the storyboard. Change the Title to say “Hello World”

Now when you click the play button you should see the simulator pop up with something like this:

Now lets make our button do something. Click on the button to make your screen go to split screen and pull up objective_C_tutorial_ViewController.h.

 

Right click on the label, holding it down drag it to the objective_C_tutorial_ViewController.h file, you will get a popup, lets name in hw_label. Repeat for the button but change the connection to action, name it hw_button:

Now pull up the objective_C_tutorial_ViewController.m file. You’ll see a new method that receives actions from the button. Lets make this toggle the label background color. Insert the code below:

– (IBAction)hw_Button:(id)sender {

if(hw_Label.backgroundColor == [UIColor orangeColor])

{

hw_Label.backgroundColor = [UIColor blueColor];

} else {

hw_Label.backgroundColor = [UIColor orangeColor];

}

}

Now when you run the simulator and push the button you will toggle the lable colors between orange and blue:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s