Created
August 19, 2012 04:19
-
-
Save lilyball/3391903 to your computer and use it in GitHub Desktop.
+[NSObject cast:]
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
@interface NSObject (Cast) | |
+ (instancetype)cast:(id)from; | |
@end | |
@implementation NSObject (Cast) | |
+ (instancetype)cast:(id)from { | |
if ([from isKindOfClass:self]) { | |
return from; | |
} | |
return nil; | |
} | |
@end |
That's backwards. You don't need a cast to assign a UIButton
value to a UIView
. It's more like
UIButton *button = [UIButton cast:someView];
if (button != nil) {
// someView was a button
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The usage here is basically this, right?