Skip to content

Instantly share code, notes, and snippets.

@chitan
Last active January 4, 2016 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chitan/8648172 to your computer and use it in GitHub Desktop.
Save chitan/8648172 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#import "MyClass.h"
@interface ChildClass : MyClass
@end
#import "ChildClass.h"
@implementation ChildClass
- (void)method
{
NSLog(@"Hello ChildClass!");
}
@end
#import <Foundation/Foundation.h>
#import "MyClass.h"
#import "ChildClass.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
MyClass *myclass = [[MyClass alloc]init];
[myclass callMyClassSelfMethod]; //Hello MyClass!
[myclass callMyClassSuperMethod]; //Hello ParentClass!
ChildClass *childclass = [[ChildClass alloc]init];
[childclass callMyClassSelfMethod]; //Hello ChildClass!
[childclass callMyClassSuperMethod]; //Hello ParentClass!
}
return 0;
}
#import <Foundation/Foundation.h>
#import "ParentClass.h"
@interface MyClass : ParentClass
- (void)callMyClassSelfMethod;
- (void)callMyClassSuperMethod;
@end
#import "MyClass.h"
@implementation MyClass
- (void)method
{
NSLog(@"Hello MyClass!");
}
- (void)callMyClassSelfMethod
{
[self method];
}
- (void)callMyClassSuperMethod
{
[super method];
}
@end
#import <Foundation/Foundation.h>
@interface ParentClass : NSObject
- (void)method;
@end
#import "ParentClass.h"
@implementation ParentClass
- (void)method
{
NSLog(@"Hello ParentClass!");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment