Created
May 15, 2013 07:30
-
-
Save advantis/5582203 to your computer and use it in GitHub Desktop.
Rough analogue of C++ static_cast and dynamic_cast
This file contains 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
// | |
// Copyright © 2012 Yuri Kotov | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSObject (ADVCasting) | |
+ (instancetype) staticCast:(id)from; | |
+ (instancetype) dynamicCast:(id)from; | |
@end |
This file contains 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
// | |
// Copyright © 2012 Yuri Kotov | |
// | |
#import "NSObject+ADVCasting.h" | |
@implementation NSObject (ADVCasting) | |
+ (instancetype) staticCast:(id)from | |
{ | |
return from; | |
} | |
+ (instancetype) dynamicCast:(id)from | |
{ | |
return [from isKindOfClass:self] ? from : nil; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment