ReactiveObjC icon indicating copy to clipboard operation
ReactiveObjC copied to clipboard

Help: How to use **rac_channelTerminalForKey:**

Open JadianZheng opened this issue 6 years ago • 0 comments

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:

  1. Change switch state, user default change the same. (Done)
  2. Change switch state, user default call the subscribeNext:. (Unhappen)
  3. Change the user default, switch state change the same. (Unhappen)

JadianZheng avatar Aug 27 '18 08:08 JadianZheng