November 2013
Beginner
325 pages
9h 47m
English
You have a perfectly good initializer for BNRAppliance, but let’s take a moment to look at a variation that you will see in other people’s code. We typically do a plain assignments in an initializer, but many programmers will use the accessor methods. Change initWithProductName: to do this:
- (instancetype)initWithProductName:(NSString *)pn
{
// Call NSObject's init method
self = [super init];
// Did it return something non-nil?
if (self) {
// Set the product name
[self setProductName:pn];
// Give voltage a starting value
[self setVoltage:120];
}
return self;
}
In most cases, there is little reason to do one over the other, but it makes for a great argument. The argument goes like this: The assign guy says, “You cannot ...
Read now
Unlock full access