#import <Foundation/Foundation.h>
@class Student;
@protocol findHouseProtocol <NSObject>
-(void)findHouse:(Student*)stu;
@end
#import <Foundation/Foundation.h>
#import "findHouseProtocol.h"
@interface LinkHouse : NSObject<findHouseProtocol>
@end
#import "LinkHouse.h"
@implementation LinkHouse
-(void)findHouse:(Student *)stu{
NSLog(@"帮%@找房子",stu);
}
@end
#import <Foundation/Foundation.h>
#import "findHouseProtocol.h"
@interface Student : NSObject
@property(nonatomic,strong)id<findHouseProtocol>delegate;
-(void)needHouse;
@end
#import "Student.h"
@implementation Student
-(void)needHouse{
NSLog(@"需要房子");
[self.delegate findHouse:self];
}
@end
#import <Foundation/Foundation.h>
#import "Student.h"
#import "LinkHouse.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Student *s = [Student new];
LinkHouse *lk=[LinkHouse new];
s.delegate = lk;
[s needHouse];
}
return 0;
}
|
|