zoukankan      html  css  js  c++  java
  • OC11_真正的代理

    //
    //  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;
    }
  • 相关阅读:
    apt常用命令(安装,更新,删除)
    记录一次坑爹的VM连接主机的路程
    VM安装centos
    初窥DB2之insert语句
    关于虚拟机的linux不能使用shell连接时的处理方法
    linux命令之查看字符集
    趣图:学JavaScript
    PHP搭建大文件切割分块上传功能示例
    判断变量是否不为空,函数isset()、!empty()与!is_null()的比较
    Javascript 中 null、NaN和undefined的区别
  • 原文地址:https://www.cnblogs.com/0515offer/p/4598615.html
Copyright © 2011-2022 走看看