1 正式协议

  • 声明协议
1
2
3
  @protocol NSCoding
  - (id) copyWithZone: (NSZone *) zone;
  @end

继承父协议:

1
2
  @protocol MySuperDuberProtocol <MyParentProtocol>
  @end
  • 采用协议
1
2
3
4
5
6
  @interface Car NSObject <NSCopying, NSCoding>
  {
  // instance variables
  }
  // methods
  @end // Car
  • 实现协议

2 复制

浅层复制 深层复制

3 @optional @required

4 委托方法

委托(delegation)是某个对象指定另一个对象处理某些特定任务的设计模式。委托经常与协议共用。