Home > 2010 Winter DPS913 > Apple development toolset introduction for Seneca SCS students

Apple development toolset introduction for Seneca SCS students

January 13, 2010 Leave a comment Go to comments

This post introduces School of Computer Studies students to the Apple development toolset – Xcode, Interface Builder, and iPhone Simulator.

We will use three development tools in this course:

  1. Xcode is an integrated development environment (IDE)
  2. Interface Builder helps you build user interfaces
  3. When running iPhone OS apps, the iPhone Simulator provides a way to run your app on your Mac.

This post introduces these tools. We may use another tool periodically, called Instruments.

Xcode is for writing code

Xcode is an IDE. It has an editor, an organizer for your source code, a compiler, a visual debugger, an app launcher, and access to documentation.

In class, there will be a brief demonstration of Xcode. We will introduce its interface, and its project orientation.

There are many keyboard shortcuts which can be used in Xcode. The following lists a few essential favourites:

Option+Command+up-arrow – Switch between the .h and the .m source code files

Esc – Show the list of completions

Ctrl+/ (slash) – Move the focus to the next argument in the statement

Type “log”, the press Ctrl+. (dot/period) – Creates the NSLog‚Ķ statement

Command+R – Build and run
Command+B – Build (use this while writing code to ensure that it will compile)

Additionally, make sure you use the following standard Mac OS keyboard shortcuts:

Command+right-arrow – Move the cursor to the end of the line of code
Command+left-arrow – Move the cursor to the beginning of the line of code

Option+right-arrow – Move the cursor to the beginning of the word on the right
Option+left-arrow – Move the cursor to the beginning of the word on the left

add the Shift key – Select while doing the above

PageUp, or PageDown – Page the viewport up or down WITHOUT moving the cursor
add the Option key – Do the above, and move the cursor too

Command+S – Save
Command+W – Close (the current project)
Command+Q – Quit
Command+O – Open

Command+C – Copy
Command+X – Cut
Command+V – Paste

Make sure you use the Esc keyboard shortcut when coding language constructs like if-then-else and (for and while) loops. Here’s how:

  1. Begin typing the name of the construct – for example, type “if” to begin an if-then-else statement
  2. Press Esc, and select the construct that you want

Also, make sure you use the Esc keyboard shortcut when implementing superclass (or protocol) method overrides. Here’s how:

  1. Type a – (dash), and a space
  2. Begin typing the name of the method – a few characters or more
  3. Press Esc, and select the method you wish to implement

Interface Builder is for building user interfaces

Interface Builder (IB) helps you build user interfaces, with drag-and-drop operations. You then configure the properties of the user interface elements, and connect the user interface elements to instance variables and methods in your code.

We recommend that you start/run Interface Builder AFTER you have Xcode running with your open project. You can open IB by double-clicking a nib document (a file with the .xib extension), which is typically located in the Classes or Resources folders of the “Groups & Files” object browser in Xcode. Then, make your edits/changes in IB, save your work (Command+S), and close IB (Command+Q). Continue to make coding/editing changes in Xcode, and open IB again when you need to.

IB is fundamentally a tool that works with nib files. As noted earlier, a nib file is an archived (“serialized” in Java/C#) object graph of user interface objects. An iPhone OS app has at least one nib file.

In class, there will be a brief demonstration of IB. We will introduce its interface and its document orientation.

Let’s discuss an example of IB’s role and use. Assume that we want to create a simple iPhone OS app that has a button and a label. When the button is tapped/clicked, a message (“Hello, World!”) appears in the label. When we use IB to create this user interface, and then save our work, the nib is saved as an archived object graph. Everything the user interface needs to launch and run is in the nib file. The application object takes care of loading our nib at app launch time, and it unarchives (“deserializes” in Java/C#) the object graph in memory. This results in objects like the button and label being instantiated and ready-to-use, with connections to objects in our classes (describe next).

When we edit a nib with IB, we can make connections to code in our classes:

  • Using the target/action pattern, we connect the appropriate button tap event to a method in the controller class
  • The method in the controller class will also need access to the user interface label so its visible text can be updated, so we connect the user interface label to an instance variable in the class

In the class code, we need to use syntax for our instance variables and methods that enables IB (and the runtime) to make these connections. We use “IBOutlet” and “IBAction” in the .h interface source code file.


IBOutlet is a macro that resolves to nothing (#define IBOutlet). There are two places where you use IBOutlet:

  1. If you are exposing an instance variable as a property, use it in the @property declaration.
  2. Otherwise, use it when you first declare the instance variable.

The IBOutlet word is placed just before the type name. IB uses this syntax to “see” the instance variable, so that a connection can be made to it from the user interface label.

Example of #1 above, in the @property declaration (assume that “NSArray *allStudents;” has already been declared as an instance variable):

@property (nonatomic, retain) IBOutlet NSArray *allStudents;

Example of #2 above, when you first declare the instance variable:

IBOutlet UILabel *lblResult;


IBAction is a macro that resolves to void (#define IBAction void). Use it as the return type when you declare the method. IB uses this syntax to “see” the method (i.e. the “action”) in the class (i.e. the “target”). Example:

- (IBAction)updateTheLabel:(id)sender;

It is customary and necessary to include the (id)sender argument, which gives you access to the object that sent the message (called the method).

In the implementation of the updateTheLabel: method, we can do the following, which will make “Hello, World!” appear in the user interface, because of the connection that IB makes between the label and the instance variable:

[lblResult setText:@"Hello, World!"];

(The setText: method is the setter for the label’s visible text. We may use this syntax a couple of times more before we make the switch to using properties full time.)

iPhone Simulator runs your iPhone OS app on your Mac

The iPhone Simulator is a Mac OS X program that simulates the visual appearance and some of the functionality of an iPhone. In Xcode, when you build and run (Command+R) your project, by default, your app is “installed” in the iPhone Simulator. Then, your app launches.

The environment simulates an iPhone OS, but it isn’t an exact and complete copy. Its hardware simulations are limited, where some features (like the camera) isn’t available, while others (motion and orientation, multi-touch) offer limited functionality. However, it does enable the iPhone OS developer to run their program without installing it on the device.

There are only a few really useful keyboard shortcuts on the iPhone Simulator:

  • Command+Shift+H – presses the “Home” button (to return to the Home screen)
  • Command+Q – quit the iPhone Simulator
  • Command+right-arrow – rotate the orientation to the right
  • Command+left-arrow – rotate the orientation to the left
  • Option – begins a two-touch sequence (for squeeze or stretch)

Categories: 2010 Winter DPS913
  1. No comments yet.
  1. January 13, 2010 at 8:11 am

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: