當想讓 view 的數(shù)據(jù)告訴給 ViewController 的時候丁逝,需要使用代理媚狰。有些麻煩,這個時候可以使用 RACSubject 來代替 代理
#import <ReactiveObjC/ReactiveObjC.h>
@interface WYView : UIView
@property (nonatomic, strong) RACSubject *subject;
@end
@implementation WYView
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[_subject sendNext:@"WYView"];
}
@end
// 調(diào)用
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
WYView *aView = [WYView new];
aView.backgroundColor = [UIColor blueColor];
aView.frame = CGRectMake(100, 100, 200, 200);
[self.view addSubview:aView];
RACSubject *subject = [RACSubject subject];
[subject subscribeNext:^(id _Nullable x) {
// 訂閱 代碼
}];
aView.subject = subject;
}
@end