码迷,mamicode.com
首页 > 其他好文 > 详细

OC9_代理正向传值

时间:2015-06-24 22:15:27      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

//
//  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;
}

 

OC9_代理正向传值

标签:

原文地址:http://www.cnblogs.com/0515offer/p/4598586.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!