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;
    }
  • 相关阅读:
    盒子模型
    css基本选择器
    css样式写法<link和style>
    将博客搬至CSDN
    Mac AndroidStudio 快捷键整理搜藏
    Android 图片黑白显示 自定义饱和度
    android studio 将包含jar包的项目打包成jar包
    JNI方法命名和方法签名
    Mac 下配置NDK/JNI开发环境,并运行简单demo
    Installation failed with message Failed to establish session报错
  • 原文地址:https://www.cnblogs.com/0515offer/p/4598586.html
Copyright © 2011-2022 走看看