ReactiveObjC
ReactiveObjC copied to clipboard
Help: How to use **rac_channelTerminalForKey:**
Demo:
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UISwitch *testSwitch;
@property (nonatomic) RACChannelTerminal *udkTerminal;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_udkTerminal = [[NSUserDefaults standardUserDefaults] rac_channelTerminalForKey:@"test"];
[_testSwitch.rac_newOnChannel subscribe:_udkTerminal];
[_udkTerminal subscribe:_testSwitch.rac_newOnChannel];
[_udkTerminal subscribeNext:^(id _Nullable x) {
NSLog(@"udk: %@", x);
}];
[_testSwitch.rac_newOnChannel subscribeNext:^(NSNumber * _Nullable x) {
NSLog(@"switch: %@", x);
}];
[self.udkTerminal sendNext:@1];
}
@end
I new a UserDefault terminal
and switch
, and subscribe them eachother. Also subscribe their next event.
Hope:
- Change
switch
state,user default
change the same. (Done) - Change
switch
state,user default
call thesubscribeNext:
. (Unhappen) - Change the
user default
,switch
state change the same. (Unhappen)