#import "ViewController.h"
#import <ReactiveObjC.h>
#import <RACReturnSignal.h>
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textfiled;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
RACSubject * subject = [RACSubject subject];
//skip: 跳跃几个值
[[subject skip:2] subscribeNext:^(id _Nullable x) {
NSLog(@"%@",x);
}];
[subject sendNext:@"1"];
[subject sendNext:@"2"];
[subject sendNext:@"3"];
}
-(void)distinDemo{
//1.创建信号
RACSubject * subject = [RACSubject subject];
//忽略掉重复数据
[[subject distinctUntilChanged] subscribeNext:^(id _Nullable x) {
NSLog(@"%@",x);
}];
//请求回来
[subject sendNext:@"abc haha hehe"];
[subject sendNext:@"hehe"];
[subject sendNext:@"1"];[subject sendNext:@"1"];
[subject sendNext:@"2"];
[subject sendNext:@"2"];
}
-(void)takeDemo{
RACSubject * subject = [RACSubject subject];
//take:指定拿前面的哪几条数据!!(从前往后)
//takeLast:指定拿前面的哪几条数据!!(从后往前)注意点:一定要写结束!!
[[subject takeLast:2] subscribeNext:^(id _Nullable x) {
NSLog(@"%@",x);
}];
[subject sendNext:@"2"];
[subject sendNext:@"3"];
[subject sendNext:@"1"];
[subject sendCompleted];
// RACSubject * subject = [RACSubject subject];
//专门做一个标记信号!!
RACSubject * signal = [RACSubject subject];
//take:指定拿前面的哪几条数据!!(从前往后)
//takeLast:指定拿前面的哪几条数据!!(从后往前)注意点:一定要写结束!!
//takeUntil:直到你的标记信号发送数据的时候结束!!!
[[subject takeUntil:signal] subscribeNext:^(id _Nullable x) {
NSLog(@"%@",x);
}];
[subject sendNext:@"2"];
//[signal sendNext:@".."];
[signal sendCompleted];//标记信号!!
[subject sendNext:@"3"];
[subject sendNext:@"1"];
[subject sendCompleted];
}
-(void)ignoreDemo{
//ignore:忽略
RACSubject * subject = [RACSubject subject];
//忽略一些值!!
RACSignal * ignoreSignal = [[[subject ignore:@"1"] ignore:@"2"] ignore:@"3"];
//订阅
[ignoreSignal subscribeNext:^(id _Nullable x) {
NSLog(@"%@",x);
}];
//发送数据
[subject sendNext:@"1"];
[subject sendNext:@"2"];
[subject sendNext:@"13"];
[subject sendNext:@"3"];
}
-(void)filterDemo{
[[_textfiled.rac_textSignal filter:^BOOL(NSString * _Nullable value) {
//value:源信号的内容
return [value length] > 5;
//返回值:就是过滤条件,只有满足这个条件,才能获取到内容
}] subscribeNext:^(NSString * _Nullable x) {
NSLog(@"%@",x);
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
5-3 RAC忽略
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 2018.2.3 目标:身心健康,财富丰盛 好种子: 1早起健康早餐,种下健康的种子,回向群里姐妹及家人身心健康 ...
- 2018.3.1 目标:身心健康,财富丰盛 好种子: 1早起健康早餐,种下健康的种子 2收拾家,回向女儿和众学子干...