Home > 2011 Fall DPS913, iOS, iOS Cocoa Touch > iOS development toolset introduction for Seneca ICT students

iOS development toolset introduction for Seneca ICT students

September 5, 2011 Leave a comment Go to comments

This post introduces students in Seneca’s School of Information and Communications Technology to the Apple iOS development toolset – Xcode, Interface Builder, and iOS Simulator.

This document was most recently updated in September 2011.

.

We will use three development tools in this course:

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

.

This post introduces these tools. We may use other tools periodically, including 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.

Note: For the Fall 2011 semester, we will be using the Xcode version 4.1 toolset. If a newer version appears during the semester, we will continue to work with version 4.1.

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

.

Keyboard shortcuts

There are many keyboard shortcuts which can be used in Xcode. Each student will receive a handout, titled “Xcode 4 Keyboard Shortcuts” on the first day of the course.

Make sure you use Xcode to help 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. A list of choices appears; select with mouse or arrow key, and press Enter

.

Also, make sure you use Xcode to help 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. A list of choices appears; select with mouse or arrow key, and press Enter

.

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.

IB is integrated into Xcode 4.

.

IB is fundamentally a tool that works with nib files. As noted earlier, a nib file is an archived (“archived” is conceptually similar to “serialized” in Java/C#) object graph of user interface objects. An iOS 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 iOS 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

IBOutlet is a macro that resolves to nothing (#define IBOutlet).

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.

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.

.

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

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.)

.

iOS Simulator runs your iOS app on the Mac

The iOS 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 iOS Simulator. Then, your app launches.

The environment simulates an iOS, but it isn’t an exact and complete emulator. 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 iOS 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)

.


.

.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: