reactive-cocoa

ReactiveCocoa combine SignalProducers into one

不羁的心 提交于 2019-12-21 11:56:20
问题 I'm using ReactiveCocoa and I have several SignalProducers let center = NSNotificationCenter.defaultCenter() let signalProducer1 = center.rac_notification(name: notificationName1, object: nil) let signalProducer2 = center.rac_notification(name: notificationName2, object: nil) let signalProducer3 = center.rac_notification(name: notificationName3, object: nil) I want to combine them into a single signal producer that produces a signal whenever one of them produces a signal. At first the

How do I create a ReactiveCocoa subscriber that receives a signal only once, then unsubscribes/releases itself?

岁酱吖の 提交于 2019-12-21 03:23:09
问题 I'm currently registering a subscriber to a property signal like this: [RACAble(self.test) subscribeNext:^(id x) { NSLog(@"signal fired!"); }]; The default functionality is that it fires every single time self.test is changed, but I just want it to fire once, and then unsubscribe. Is there a "once" argument or modifier I can pass to RAC when I create this subscriber? 回答1: [[RACAble(self.test) take:1] subscribeNext:^(id x) { NSLog(@"signal fired!"); }]; 回答2: That might be helpful especially

Approach to Reactifying delegate methods with side effects

半城伤御伤魂 提交于 2019-12-20 11:08:34
问题 Just trying to wrap my head around the ReactiveCocoa approach to certain situations. I have a situation where a segment controller swaps out children view controllers. I need to accomplish a couple things here: When moved to the parent controller, I must update the contentInset of the tableView because iOS7 doesn't handle it for me with custom container views When search is initiated, I need to fade the navigation bar, and update the contentInset with animation When search ends, I need to

Splitting an RACSignal to eliminate state

我只是一个虾纸丫 提交于 2019-12-20 08:06:30
问题 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

Binding a UISwitch's state to a model with ReactiveCocoa

假如想象 提交于 2019-12-19 08:31:20
问题 I am trying to bind a UISwitch's on state to a boolean property in my model using ReactiveCocoa. I started with: RACChannelTo(self.switch, on, @NO) = RACChannelTo(self.model, toggle, @NO); This is how I've been binding other views to other parts of my model, unfortunately it didn't appear to do anything for the UISwitch. The model's state does not affect the switch, or vice versa. So I tried: RACChannelTo(self.model, toggle, @NO) = [self.switch rac_newOnChannel]; This appears to work ok, but

How to make RACSignal to become hot?

孤街浪徒 提交于 2019-12-19 03:38:23
问题 ReactiveCocoa can convert the signal to "hot" signal by calling its -subscribeCompleted: . But I think this method is quite verbose if you do not care about the result (i.e. no subscribers). RACDisposable *animationDisposable = [[self play:animation] subscribeCompleted:^{ // just to make the animation play }]; And these 3 lines are not expressive enough to show my intention. Is there any method for similar purpose? Thanks! 回答1: I want to do nothing except making it hot (=make it run once).

How do I wait in a flattenMap block for a signal to complete before the next event is consumed?

风格不统一 提交于 2019-12-13 08:08:14
问题 here is my pseudo code : [[[@[ctx1,ctx2]rac_sequence]signalWithScheduler:RACScheduler.immediateScheduler] flattenMap:^RACStream *(id ctx) { // first flatten map return [RACSignal createSignal:^(id <RACSubscriber> subscriber) { [executeRequestAsynch onDone:^{ [subscriber sendNext:ctx]; [subscriber sendCompleted]; } ] }] flattenMap:^RACStream *(id ctx) { // second flattenMap }]; } Now here is what I want to happen upon subscribe: 1) ctx1 should get fed to the first flattenMap block 2) the

What is a correct alternative for subscribing to signals in ReactiveCocoa for network calls?

允我心安 提交于 2019-12-13 06:30:00
问题 I'm new to ReactiveCocoa world and after reading best practices of ReactiveCocoa here I knew that I need to "avoid explicit subscriptions and disposal" but in all tutorials about network and ReactiveCocoa I saw the same pattern : create signal (make GET or POST request to server, parse result, sendNext , sendCompleted ) -> subcsribeNext (do UI stuff or something other with the result) -> subscribeError . So as we see there is an explicit subscription here, which is not good, I think. Are

How to merge multiple signal and stop on first next but not to stop on first error?

痴心易碎 提交于 2019-12-13 02:11:15
问题 I have a number of network requests and one or more of them will return valid data and is possible that some will return an error. How can I combine this request to stop once the first valid returned the data but not to stop in case of error. I have try like this: [[RACSignal merge:@[sigOne, sigTwo, sigThree]] subscribeNext:^(RACTuple *myData){ NSLog(@"Data received"); } error:^(NSError *error) { NSLog(@"E %@", error); } completed:^{ NSLog(@"They're all done!"); } ]; My problems: if one of

Error: 'String' is not convertible to 'String!'

纵饮孤独 提交于 2019-12-12 18:24:51
问题 mapView.rac_valuesForKeyPath("userTrackingMode", observer: self).subscribeNextAs { // block handling I get an error 'String' is not convertible to 'String!' . Any suggestions what this may mean? I used to think, that String! is same as String , so it is unwrapped String? ... Xcode 7.3.1 Swift 2.2 ReactiveCocoa 4.1.0 回答1: I think the compiler is reporting a wrong error. You can simplify the expression using let key: String! = "userTrackingMode" and then use key instead of the literal. That