fly.h:
#import <Foundation/Foundation.h> @protocol Fly -(void) go; -(void) stop; @optional -(void) sleep; @end
FlyTest.h:
#import <Foundation/Foundation.h> #import "Fly.h" @interface FlyTest : NSObject<Fly> { } @end
fly.m:
#import "FlyTest.h" @implementation FlyTest -(void) go { NSLog(@"go"); } -(void)stop { NSLog(@"stop"); } @end
main.m:
#import <Foundation/Foundation.h> #import "FlyTest.h" int main(void) { @autoreleasepool { FlyTest *flyTest=[[FlyTest alloc]init]; [flyTest go]; [flyTest stop]; } return 0; }
console log:
2013-09-18 17:48:40.156 Obj-c[1929:303] go
2013-09-18 17:48:40.160 Obj-c[1929:303] stop