043.@protocol 正式协议

来源:互联网 发布:js frame 高度 编辑:程序博客网 时间:2024/04/28 07:30
---------------  FKOutput.h  ---------------
@protocolFKOutput
@optional
- (
void) output;
@required
- (
void) addData: (NSString*) msg;
@end
---------------  FKPrintable.h  ---------------
#import<Foundation/Foundation.h>
#import
"FKOutput.h"
#import"FKProductable.h"
@protocolFKPrintable <FKOutput , FKProductable>
@required
- (NSString*) printColor;
@end
---------------  FKProductable.h  ---------------
#import<Foundation/Foundation.h>
@protocolFKProductable
- (NSDate*) getProduceTime;
@end

一、编写本节代码的具体步骤:
1.本节代码非可运行代码。

二、本节代码涉及到的知识点:
1.正式协议的关键字是@protocol。
2.定义协议的语法格式是:
  @protocol 协议名 <父协议1, 父协议2, ...>
  {
     零到多个方法定义...
  }
3.协议可以继承多个父协议。
4.协议中只有方法签名,没有方法实现。
5.协议中的方法,既可以是类方法,也可以是实例方法。
0 0