Skip to content

Instantly share code, notes, and snippets.

@PsychoH13
Created May 2, 2013 18:09
Show Gist options
  • Save PsychoH13/5504107 to your computer and use it in GitHub Desktop.
Save PsychoH13/5504107 to your computer and use it in GitHub Desktop.
Message to super
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
@interface Superclass1 : NSObject
- (void)testMethod;
@end
@interface Superclass2 : NSObject
- (void)testMethod;
@end
@interface Subclass : Superclass1
@end
int main(int argc, const char * argv[])
{
@autoreleasepool
{
Subclass *obj = [[Subclass alloc] init];
[obj testMethod];
class_setSuperclass([Subclass class], [Superclass2 class]);
[obj testMethod];
}
return 0;
}
@implementation Superclass1
- (void)testMethod;
{
NSLog(@"Superclass1");
}
@end
@implementation Superclass2
- (void)testMethod;
{
NSLog(@"Superclass2");
}
@end
@implementation Subclass
- (void)testMethod;
{
[super testMethod];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment