Skip to content

Instantly share code, notes, and snippets.

@karolkozub
Created January 9, 2015 13:03
Show Gist options
  • Save karolkozub/0507f79cbc6765c16b43 to your computer and use it in GitHub Desktop.
Save karolkozub/0507f79cbc6765c16b43 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
@interface A : NSObject - (void)abc; @end
@interface B : A @end
@interface C : B @end
@implementation A - (void)abc { NSLog(@"-[A abc]"); } @end
@implementation B - (void)abc { NSLog(@"-[B abc]"); } @end
@implementation C - (void)abc { NSLog(@"-[C abc]"); }
-(void)abc_A { struct objc_super sup = {self, [A class]}; objc_msgSendSuper(&sup, @selector(abc)); }
-(void)abc_B { struct objc_super sup = {self, [B class]}; objc_msgSendSuper(&sup, @selector(abc)); }
-(void)abc_C { struct objc_super sup = {self, [C class]}; objc_msgSendSuper(&sup, @selector(abc)); }
@end
int main(int argc, char *argv[]) {
[[C new] abc_A];
[[C new] abc_B];
[[C new] abc_C];
}
// Prints out:
// -[A abc]
// -[B abc]
// -[C abc]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment