首先创建一个协议的头文件
@protocol BiteDelegate <NSObject>
@optional
- (void)biteSomeone:(id)someone;
@end
person.h中声明以下代码
#import "Dog.h"
#import "BiteDelegate.h"
#import <Foundation/Foundation.h>
typedef int * Pointer;
@interface Person : NSObject
@property (nonatomic, strong) Dog *dog;
@property (nonatomic, strong) id something;
@property (nonatomic, strong) id<BiteDelegate> delegate;
- (void)print;
@end
person.h
#import "Person.h"
@implementation Person
- (void)print
{
int a = 10;
Pointer pa = &a;
*pa = 30;
NSLog(@"%d", a);
}
@end
Dog.h
#import <Foundation/Foundation.h>
#import "BiteDelegate.h"
@interface Dog : NSObject <BiteDelegate>
@end
Dog.m
#import "Dog.h"
@implementation Dog
- (void)biteSomeone:(id)someone
{
NSLog(@"%@", someone);
}
@end