Instancetype


#1

On page 50, in the instancetype section it says …

Isn’t it the other way around? And if not, could you please explain the concept in further detail.

Thanks!


#2

No, it’s right. It’s saying that if you have something that subclasses BNRItem, calling the initializer on it would return that subclass. The problem is that if we didn’t use (instancetype) to define its return value and used (BNRItem *) instead, we would have a conflict since we are returning the subclass of BNRItem, not a BNRItem itself.


#3

I think I got it now. It took several more passes at it until it began to make sense. Thank you for taking the time to clear that up for me!


#4

Just so I get this straight cause i think the way its written is a little confusing. When it says “If an instance of the subclass was sent this initializer message, what would be returned?” are they talking about this initializer:

- (instancetype)initWithItemName:(NSString *)name valueInDollars:(int)value serialNumber:(NSString *)sNumber;

are they saying this init method will return an instance of the subclass?