Casting has no runtime effect. This is just a message to the compiler that you are sure that it can be assigned from one type to another (it will also turn off warnings that โmay not respondโ when you have an id ).
NSString * s = (NSString *)[NSNumber numberWithInt:0];
On the other hand, isKindOfClass: does not affect compilation time; it is sent, like any other message, at runtime, and its result is then determined.
Iโm not sure what you are trying to achieve, but I canโt come up with anything useful that could be done by combining these two mechanisms.
There is no reason to send isKindOfClass: before casting, but not for the reasons you think. Either you know the class at compile time, and in this case isKindOfClass: pointless or not, in which case casting is inefficient.
source share