Honors Software Design - iOS Name -
Learn Objective-C in 6 Days Worksheet #4
Answer the following after reading http://mobile.tutsplus.com/tutorials/iphone/learn-objective-c-day-4/
1. Why is Cocoa.h imported (aka included) in this tutorial?
2. Why is the : NSObject typed out in the line of code @interface SimpleCar : NSObject
3. Rewrite the line of code that declares the vin attribute in the SimpleCar interface.
4. Rewrite the line of code that declares the setter method for the vin attribute.
5. What is the name for the setter method of the vin attribute?
6. What is the name of the argument that is passed to the setVin method?
7. What data type does the argument for the setVin method have?
8. Rewrite the complete declaration for the method in the SimpleCar interface that takes two arguments.
9. What is the name of this method?
10. What are the two arguments for this method?
11. What is the naming convention for getter methods?
12. Rewrite the complete implementation for the getter method of the vin attribute.
13. What is the return type (i.e. data type) for the vin attribute's getter method?
14. Since our SimpleCar interface doesn't have a constructor like it would in Java, you must use alloc and init for each attribute in the attribute's setter method. But why must the statement [vin release]; be used in the vin attribute setter?
15. What is the role of the dealloc method?
16. Explain each statement of the following client program in your own words with a comment like the example:
#import "SimpleCar.h" // necessary to include the interface for SimpleCar since the class is not bundled in the Foundation classes
...
SimpleCar *myCar = [[SimpleCar alloc] init];
NSNumber *newVin = [NSNumber numberWithInt:123];
[myCar setVin:newVin];
[myCar setMake:@"Honda" andModel:@"Civic"];
NSLog(@"The car is: %@ %@", [myCar make], [myCar model]);
NSLog(@"The vin is: %@", [myCar vin]);
17. How can @property and @synthesize be used to simplify the interface and implementation of a class?