Homework 1 — Categories

Due Monday, February 22, 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, subclassing some classes can be quite difficult in Objective-C. For example, it is very difficult to subclass NSArray because it defines a class cluster, a complicating factor with which any subclass must deal. However, if the reason for wanting to subclass an existing class is to use the features of that class and add a method, this can be done by creating a category of that class instead.

The assignment.

Create a category of the NSMutableArray class that adds a method to randomize the order of the elements in the array. This should be similar in effect to the shuffle method of the Collections class in Java.

What to turn in.

Turn in both printed and electronic copies of the code, including the interface, the implementation, and appropriate test code to demonstrate the functionality of your category. If you started from code from any other source, be sure to document that in the comments of your code.