zoukankan      html  css  js  c++  java
  • OC9_代理正向传值

    //
    //  ProtectedDeleagate.h
    //  OC9_代理正向传值
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @protocol ProtectedDeleagate <NSObject>
    - (void)bark:(NSInteger)count;
    
    @end
    
    
    
    //
    //  Person.h
    //  OC9_代理正向传值
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "ProtectedDeleagate.h"
    
    @interface Person : NSObject
    //{
    //   __unsafe_unretained id <ProtectedDeleagate>_delegate;
    //}
    @property (nonatomic,assign)id <ProtectedDeleagate>delegate;
    
    @property (nonatomic)NSInteger count;
    
    - (void)go;
    
    @end
    
    
    
    //
    //  Person.m
    //  OC9_代理正向传值
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "Person.h"
    
    @implementation Person
    
    - (void)go
    {
        [_delegate bark:self.count];
    }
    @end
    
    
    
    //
    //  Dog.h
    //  OC9_代理正向传值
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "ProtectedDeleagate.h"
    
    @interface Dog : NSObject <ProtectedDeleagate>
    
    @end
    
    
    
    //
    //  Dog.m
    //  OC9_代理正向传值
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "Dog.h"
    
    @implementation Dog
    
    - (void)bark:(NSInteger)count
    {
        for (NSInteger i=0; i<count; i++) {
            NSLog(@"Wang wang wang ...");
        }
    }
    
    @end
    //
    //  main.m
    //  OC9_代理正向传值
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "Dog.h"
    #import "Person.h"
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            Person *xiaoXin = [[Person alloc] init];
            xiaoXin.count = 5;
            Dog *dog = [[Dog alloc] init];
            xiaoXin.delegate = dog;
            [xiaoXin go];
        }
        return 0;
    }
  • 相关阅读:
    10.30NOIP集训总结
    【JZOJ5363】【NOIP2017提高A组模拟9.14】生命之树 Trie+启发式合并
    【JZOJ5338】【NOIP2017提高A组模拟8.25】影子 点分治?/ 排序
    2017.08.13涉猎题集
    【JZOJ5233】【GDOI模拟8.5】概率博弈 树形dp+期望
    【JZOJ5231】【NOIP2017模拟A组模拟8.5】序列问题 线段树
    java8 对List<对象>获取某个属性并去重
    jquery 获取多选select的文本中并拼接成字符串
    idea 配置maven web项目
    如何做PPT
  • 原文地址:https://www.cnblogs.com/0515offer/p/4598586.html
Copyright © 2011-2022 走看看