Is there anything like C++s safe casts in Objective-C?
I know that they are in Objective C++, but I am unsure about possible side effects. Using Objective C++ may slow compilation time - are there any other reasons not to use it?
Objective-c does have C++ safe casts. Alternatively, we can use runtime reflection:
id myOb=[someObject getObject];
NSAssert([myOb isKindOfClass:[MyClass class]], @"Return value is not of type MyClass as expected.");
MyClass * newOb= (MyClass *)myOb;
References:
Cocoa with Love:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With