当前位置: 移动技术网 > 移动技术>移动开发>IOS > 完整代理的简单实现

完整代理的简单实现

2018年09月26日  | 移动技术网移动技术  | 我要评论

main.m文件

#import <foundation/foundation.h>
#import "person.h"
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        person *xw = [person new];
        [xw needhouse:@"小区房"];
    }
    return 0;
}

agent.h

#import <foundation/foundation.h>

@protocol renthousedelegate<nsobject>
- (void) renthousedidfinished:(nsstring *)result;
@end
@interface agent : nsobject
@property (nonatomic,assign) id <renthousedelegate>delegate;
- (nsstring *)renthouse;
@end

agent.m

#import "agent.h"

@implementation agent
- (nsstring *)renthouse{
    if (self.delegate != nil) {
        nsstring *result = @"房子找到了,为**小区3栋405";
        [self.delegate renthousedidfinished:result];
        return result;
    }
    return nil;
}

@end

person.h

#import <foundation/foundation.h>
#import "agent.h"
@interface person : nsobject<renthousedelegate>
- (void) needhouse:(nsstring *)require;

@end

person.m

#import "person.h"

@implementation person
- (void)needhouse:(nsstring *)require{
    //1.找到中介(需要导入中介类)
    agent *agent = [agent new];
    //2.告诉中介我是谁,(在这里就需要在中介类定义一个属性进行记录)
    agent.delegate = self;
    //3.中介去租房子,(在这里需要在中介类里面定义一个租房子的方法)
    [agent renthouse];
}
- (void)renthousedidfinished:(nsstring *)result{
    nslog(@"%@",result);
}
@end

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网