To be or not to be.That is a question!

---源于莎士比亚的《哈姆雷特》

导航

协议(porotocol)

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

posted on 2013-09-18 17:51  Ijavascript  阅读(312)  评论(0编辑  收藏  举报