Skip to content

Instantly share code, notes, and snippets.

@norio-nomura
Created October 4, 2012 02:14
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save norio-nomura/3831099 to your computer and use it in GitHub Desktop.
Save norio-nomura/3831099 to your computer and use it in GitHub Desktop.
How to call objc_msgSendSuper()
//
// AppDelegate.m
// CallSuperMethod
//
#import <objc/objc-runtime.h>
#import "AppDelegate.h"
@interface Superclass : NSObject
- (NSString*)a;
@end
@implementation Superclass
- (NSString*)a;
{
return @"Super";
}
@end
@interface Subclass : Superclass
- (NSString*)a;
@end
@implementation Subclass
- (NSString*)a;
{
return @"Subclass";
}
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
Subclass *subclass = [Subclass new];
NSLog(@"[subclass a]:%@",[subclass a]);
struct objc_super superInfo = {
subclass,
[subclass superclass]
};
NSLog(@"[[subclass super] a]:%@",objc_msgSendSuper(&superInfo, @selector(a)));
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment