1.RACSubject继承RACSignal,与RACSignal不同的是,RACSubject自身就可以信号的创建,订阅与发送
//创建信号
RACSubject *subject = [RACSubject subject];
//订阅信号
[subject subscribeNext:^(id _Nullable x) {
NSLog(@"%@", x);
}];
//发送信号
[subject sendNext:@"信号"];
2.RACReplaySubject继承RACSubject,与RACSubject不同,RACReplaySubject关心历史信号,会进行输出
RACReplaySubject *subject =[RACReplaySubject subject];
[subject sendNext:@"RACReplaySubject"];
[subject subscribeNext:^(id _Nullable x) {
NSLog(@"%@", x);
}];
RACSubject *subject2 = [RACSubject subject];
[subject2 sendNext:@"RACSubject"];
[subject2 subscribeNext:^(id _Nullable x) {
NSLog(@"%@", x);
}];
运行结果:
运行结果
可见RACSubject对订阅前的信号进行了忽略。
网友评论