Created
December 2, 2013 01:40
-
-
Save nsforge/7743616 to your computer and use it in GitHub Desktop.
Example of why you shouldn't blindly throw away type information from the compiler when casting to a protocol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)someCallbackWithAViewController:(UIViewController *)viewController | |
{ | |
if ([viewController conformsToProtocol:@protocol(CrazyViewController)]) | |
{ | |
UIViewController <CrazyViewController> *crazyVC = (UIViewController <CrazyViewController> *)viewController; | |
if (crazyVC.presentedViewController == nil) | |
{ | |
[crazyVC showCrazyModalView]; | |
} | |
else | |
{ | |
[crazyVC startCrazyViewHideTransition]; | |
} | |
} | |
else | |
{ | |
// do something different | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you had cast
crazyVC
to(id <CrazyViewController>)
, you would get a compiler error on line 6.