reactive-cocoa

What are the reference ownership semantics of ReactiveCocoa?

我怕爱的太早我们不能终老 提交于 2019-12-02 14:18:34
When I create a signal and bring it into the scope of a function, its effective retain count is 0 per Cocoa conventions: RACSignal *signal = [self createSignal]; When I subscribe to the signal, it retains the subscriber and returns a disposable which, per Cocoa conventions, also has a retain count of zero. RACDisposable *disposable = [signal subscribeCompleted:^ { doSomethingPossiblyInvolving(self); }]; Most of the time, the subscriber will close over and reference self or its ivars or some other part of the enclosing scope. So when you subscribe to a signal, the signal has an owning reference

Splitting an RACSignal to eliminate state

纵饮孤独 提交于 2019-12-02 14:15:37
I'm using ReactiveCocoa to update a UILabel whilst a UIProgressView counts down: NSInteger percentRemaining = ...; self.progressView.progress = percentRemaining / 100.0; __block NSInteger count = [self.count]; [[[RACSignal interval:0.05 onScheduler:[RACScheduler mainThreadScheduler]] take: percentRemaining] subscribeNext:^(id x) { count++; self.countLabel.text = [NSString stringWithFormat:@"%d", count]; self.progressView.progress = self.progressView.progress - 0.01; } completed:^{ // Move along... }]; This works well enough but, I'm not particularly happy with either the count variable or with

Two way binding in RxSwift

白昼怎懂夜的黑 提交于 2019-11-30 13:39:30
I read the two way binding operator in sample code of RxSwift. func <-> <T>(property: ControlProperty<T>, variable: Variable<T>) -> Disposable { let bindToUIDisposable = variable.asObservable() .bindTo(property) let bindToVariable = property .subscribe(onNext: { n in variable.value = n }, onCompleted: { bindToUIDisposable.dispose() }) return StableCompositeDisposable.create(bindToUIDisposable, bindToVariable) } When property changed, it will notify variable, and set the variable's value, while the variable's value is set, it will notify the property. I think it will lead to endless loop...

Remove a ReactiveCocoa signal from a control

瘦欲@ 提交于 2019-11-30 10:37:55
If I assign a signal to a property of a control: RAC(self.loginButton.enabled) = [RACSignal combineLatest:@[ self.usernameTextField.rac_textSignal, self.passwordTextField.rac_textSignal ] reduce:^(NSString* username, NSString* password) { return @(username.length > 0 && password.length > 0); }]; But then wanted to assign a different RACSignal to enabled , how can I clear any existing one before doing so? If I try and set it a second time, I get an exception like the following: 2013-10-29 16:54:50.623 myApp[3688:c07] *** Terminating app due to uncaught exception

Retrying an asynchronous operation using ReactiveCocoa

放肆的年华 提交于 2019-11-30 09:52:20
I'm using ReactiveCocoa signals to represent calls to RESTful backend in our system. Each RESTful invocation should receive a token as one of the parameters. The token itself is received from authentication API call. All works fine and we're now introduced token expiration, so the backend access class may need to reauthorize itself if the API call fails with HTTP code 403. I want to make this operation completely transparent for the callers, this is the best I came up with: - (RACSignal *)apiCallWithSession:(Session *)session base:(NSString *)base params:(NSDictionary *)params get:(BOOL)get {

Combine signals in ReactiveCocoa to a new one that fires when all change

一笑奈何 提交于 2019-11-30 07:28:24
I'm trying to learn ReactiveCocoa and I'm writing a simple Space Invaders clone, based on a Ray Wenderlich tutorial. Lately during the development, I faced an issue I can't resolve. Basically I've two signals: a tap gesture signal a timed sequence that fires every second What I want to achieve is to combine these signals in a new one, that fires when both the signals change: is it possible? I saw the combineLatest method, but the block is execute whenever any signals change. My wanted pseudocode is: RACSignal *updateEventSignal = [RACSignal interval:1 onScheduler:[RACScheduler

How can I subscribe to the completion of a command's execution signals without a nested subscription?

♀尐吖头ヾ 提交于 2019-11-30 05:27:31
I tried the following without success. The equivalent using -subscribeNext: works as expected. // A [[_viewModel.loginCommand.executionSignals flatten] subscribeCompleted:^{ NSLog(@"A"); }]; My only working implementation is as follows: // B [_viewModel.loginCommand.executionSignals subscribeNext:^(RACSignal *loginSignal) { [loginSignal subscribeCompleted:^{ NSLog(@"B"); }]; }]; Why doesn't -flatten work in "A", and how I can I rewrite "B" to not use a nested subscription? The -flatten operator returns a signal that completes only when all of the inner signals have completed, which requires

Two way binding in RxSwift

删除回忆录丶 提交于 2019-11-29 18:37:35
问题 I read the two way binding operator in sample code of RxSwift. func <-> <T>(property: ControlProperty<T>, variable: Variable<T>) -> Disposable { let bindToUIDisposable = variable.asObservable() .bindTo(property) let bindToVariable = property .subscribe(onNext: { n in variable.value = n }, onCompleted: { bindToUIDisposable.dispose() }) return StableCompositeDisposable.create(bindToUIDisposable, bindToVariable) } When property changed, it will notify variable, and set the variable's value,

Combine signals in ReactiveCocoa to a new one that fires when all change

拜拜、爱过 提交于 2019-11-29 10:11:22
问题 I'm trying to learn ReactiveCocoa and I'm writing a simple Space Invaders clone, based on a Ray Wenderlich tutorial. Lately during the development, I faced an issue I can't resolve. Basically I've two signals: a tap gesture signal a timed sequence that fires every second What I want to achieve is to combine these signals in a new one, that fires when both the signals change: is it possible? I saw the combineLatest method, but the block is execute whenever any signals change. My wanted

How can I subscribe to the completion of a command's execution signals without a nested subscription?

喜你入骨 提交于 2019-11-29 03:57:32
问题 I tried the following without success. The equivalent using -subscribeNext: works as expected. // A [[_viewModel.loginCommand.executionSignals flatten] subscribeCompleted:^{ NSLog(@"A"); }]; My only working implementation is as follows: // B [_viewModel.loginCommand.executionSignals subscribeNext:^(RACSignal *loginSignal) { [loginSignal subscribeCompleted:^{ NSLog(@"B"); }]; }]; Why doesn't -flatten work in "A", and how I can I rewrite "B" to not use a nested subscription? 回答1: The -flatten