RACSubject *subject = [RACSubject subject];
[[subject filter:^BOOL(NSString *value) {
return value.length > 2;
}] subscribeNext:^(id x) {
NSLog(@"%@", x);
}];
[subject sendNext:@"132"];
```
* 1.2, ignore,忽略掉需要忽略的值
RACSubject *subject01 = [RACSubject subject];
[[subject01 ignore:@(3)] subscribeNext:^(id x) {
NSLog(@"%@",x);
}];
[subject01 sendNext:@3];
* 1.3, take,从前面一共取几次,也就是可以接受几次数据
RACSubject *subject02 = [RACSubject subject];
[[subject02 take:2] subscribeNext:^(id x) {
NSLog(@"%@", x);
}];
[subject02 sendNext:@"第一次"];
[subject02 sendNext:@"第二次"];
[subject02 sendNext:@"第三次"];
[subject02 sendNext:@"第四次"];
* 1.4, takeLast,从后往前一共取几次数据,需要发送完成信息
RACSubject *subject03 = [RACSubject subject];
[[subject03 takeLast:2] subscribeNext:^(id x) {
NSLog(@"%@", x);
}];
[subject03 sendNext:@"第一次"];
[subject03 sendNext:@"第二次"];
[subject03 sendNext:@"第三次"];
[subject03 sendNext:@"第四次"];
[subject03 sendCompleted];
```
- 1.5, takeUntil,执行直到遇到until后面的那个信号
RACSubject *subject04 = [RACSubject subject];
RACSubject *endSignal = [RACSubject subject];
[[subject04 takeUntil:endSignal] subscribeNext:^(id x) {
NSLog(@"%@", x);
}];
[subject04 sendNext:@"第一次"];
[subject04 sendNext:@"第二次"];
[endSignal sendCompleted];
[subject04 sendNext:@"第三次"];
[subject04 sendNext:@"第四次"];
```
* 1.6, distinctUntilChanged,过滤掉重复的值
RACSubject *subject05 = [RACSubject subject];
[[subject05 distinctUntilChanged] subscribeNext:^(id x) {
NSLog(@"%@", x);
}];
[subject05 sendNext:@"第一次"];
[subject05 sendNext:@"第二次"];
[subject05 sendNext:@"第二次"];//这次是重复的,所以就不会接受这个数据
[subject05 sendNext:@"第三次"];
[subject05 sendNext:@"第四次"];
* 1.7,skip,跳过前面几个值
```
RACSubject *subject06 = [RACSubject subject];
[[subject06 skip:1] subscribeNext:^(id x) {
NSLog(@"%@", x);
}];
[subject06 sendNext:@"第一次"];
[subject06 sendNext:@"第二次"];
[subject06 sendNext:@"第三次"];
[subject06 sendNext:@"第四次"];