I have a problem with classes. This is my code:
self.shapeClass = [HWRectangle class];
if ([_shapeClass isKindOfClass:[HWRectangle class]]) {
NSLog(@"Class created as: %s", [_shapeClass description]);
}
I thought that the program will do the logging in this case, but it doesn’t. Do you have any idea why not?
because:
if ([_shapeClass isKindOfClass:[HWRectangle class]])_shapeClassshould be an instance of the class you are testing, unless you are really testing for class comparisons. So, this method is instance to class comparison, not class to class comparison.For bonus points, your format string should be:
NSLog(@"Class created as: %@", [_shapeClass description])(unless you have overridden the NSObject method (which you should not do))