//
// ReceiveReportDelegate.h
// OC11_真正的代理
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol ReceiveReportDelegate <NSObject>
- (
void)report:(NSInteger)count;
@end
//
// MarsPerson.h
// OC11_真正的代理
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ReceiveReportDelegate.h"
@interface MarsPerson : NSObject <ReceiveReportDelegate>
@end
//
// MarsPerson.m
// OC11_真正的代理
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import "MarsPerson.h"
@implementation MarsPerson
- (
void)report:(NSInteger)count
{
NSLog(@"killed %li people",count);
}
@end
//
// Person.h
// OC11_真正的代理
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ReceiveReportDelegate.h"
@interface Person : NSObject <ReceiveReportDelegate>
@end
//
// Person.m
// OC11_真正的代理
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import "Person.h"
@implementation Person
- (
void)report:(NSInteger)count
{
NSLog(@"killed %li people", count);
}
@end
//
// Dog.h
// OC11_真正的代理
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ReceiveReportDelegate.h"
@interface Dog : NSObject
@property (assign,nonatomic) id <ReceiveReportDelegate>
delegate;
- (
void)bark;
@end
//
// Dog.m
// OC11_真正的代理
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import "Dog.h"
@implementation Dog
- (
void)bark
{
NSLog(@"Wang wang wang ...");
[self.delegate report:arc4random()%
100+
1];
}
@end
//
// main.m
// OC11_真正的代理
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Person.h"
#import "MarsPerson.h"
#import "Dog.h"
int main(
int argc,
const char *
argv[]) {
@autoreleasepool {
Dog *dog =
[[Dog alloc] init];
Person *xiaoHua =
[[Person alloc] init];
dog.delegate =
xiaoHua;
[dog bark];
MarsPerson *xiaoXin =
[[MarsPerson alloc] init];
dog.delegate =
xiaoXin;
[dog bark];
}
return 0;
}
转载于:https://www.cnblogs.com/0515offer/p/4598615.html