I always wonder, should we use NSClassFromString before using any built in class in our code to make is generic. Or is there any standard practice to use this. Same thing for property. Should we use valueForKey and setValue calls separately to access any property. Is it a standard practice?
For example look at the below code
// Screen scaling
if ([self respondsToSelector:@selector(setContentsScale:)])
{
Class screenClass = NSClassFromString(@"UIScreen");
if ( screenClass != Nil)
{
id scale = [[screenClass mainScreen] valueForKey:@"scale"];
[(id)self setValue:scale forKey:@"contentsScale"];
}
}
Here everything is checked before use. Is it required to do this and what about performance?