Homework 4 — Objective-C Syntax

Due Friday, March 26, 2010

NOTE: The hard copy of this assignment, like others in this class, is due at the beginning of the class period. This means that if you are even a minute late, you lose 20%. If you are worried about potentially being late, turn in your assignment ahead of time. Do this by submitting it to me during office hours or by sliding it under my office door. The electronic copy of this assignment is due at 9:00pm on the due date. Submit the electronic copy using the appropriate dropbox in D2L. Do not send assignments to me through email or leave them in my departmental mail box.

As discussed in class and in your readings, Objective-C has a slightly different syntax than that of other OO languages. In some cases, this difference means that there are slightly different ways to represent the same thing, yet in other cases it can have a profound effect on how the code functions.

The assignment.

  1. Explain what id is and how it is used.


  2. Label and explain the parts of the following class declaration.
        @interface SampleAppDelegate : NSObject <UIApplicationDelegate>
    Note that you do not need to describe what objects of the class do, only tell why the parts are important.


  3. Label and explain the parts of the following method declaration.
        -(void) setNumerator: (int) n andDenominator: (int) d;
    Note that you do not need to describe what the method will do, only tell why the parts are important.


  4. Label and explain the parts of the following line of code.
        [myCircle setCenter: [myRectangle center] andRadius: 4.5];
    Note that you do not need to describe what the objects will do, only tell why the parts are important.


  5. Explain what will happen if, when the line of code above is executed, myRectangle is nil.


  6. Explain the difference between how this line of code would execute in C and Objective-C.
        myThing.thePart = newData;
    Explain why this difference is significant.

What to turn in.

Turn in both printed and electronic copies of your answers.