Last active
December 12, 2015 05:28
-
-
Save juniovitorino/4722167 to your computer and use it in GitHub Desktop.
Invoking class methods
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
@interface Person : NSObject | |
+(BOOL) walking; | |
@end | |
@interface Philip : Person | |
+(BOOL) walking; | |
@end | |
@implementation Philip | |
+(BOOL) walking | |
{ | |
NSLog(@"Who are walking?"); | |
return YES; | |
} | |
// And in some use case you can | |
// This way it use Person walk version | |
if([Person walking]) NSLog(@"A person is walking"); | |
// This way if Philip implement walk your version is called | |
// If not the inherited version is called | |
if([[self class] walk]) NSLog(@"Philip is walking"); | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thats super.. thanks a lot.. [self class] walk] makes the code even safer. :)