isKindOfClass
returns true when an object inherits from (or is) a given class. In this case, it’s checking if images
is a NSArray
or a subclass of NSArray
.
An example of usage in some code I’m working on is checking if the item we’re displaying needs to be handled for an iPad ([ctrl isKindOfClass:[BaseSplitViewController class]]
) or the iPhone. Like this:
CGRect backViewFrame = CGRectZero;
if ([currentController isKindOfClass:[BaseSplitViewController class]]) {
//Set width and hight of background View to 1024.
[backgroundView setFrame:CGRectMake(0, 0, 1024, 1024)];
if (UIInterfaceOrientationIsLandscape(orientation)) {
backViewFrame = CGRectMake(0, 0, 1024, 768);
} else if (UIInterfaceOrientationIsPortrait(orientation)) {
backViewFrame = CGRectMake(0, 0, 768, 1024);
}
} else {
backViewFrame = currentController.view.frame;
[backgroundView setFrame:backViewFrame];
}
4
solved what is “isKindOfClass” and why we use it? [closed]