November 2013
Beginner
325 pages
9h 47m
English
Sometimes an object cannot be initialized properly without some information from the method that is calling it. For example, imagine that an appliance cannot function without a name. (nil does not count.) In this case, you need to be able to pass the initializer a name to use.
You cannot do this with init because, for now and always, init has no arguments. So you have to create a new initializer instead. Then, when another method creates an instance of BNRAppliance, it would look like this:
BNRAppliance *a = [[BNRAppliance alloc] initWithProductName:@"Toaster"];
The new initializer for BNRAppliance is initWithProductName:, and it accepts an NSString as an argument. Declare this new method in BNRAppliance.h ...
Read now
Unlock full access