reactive-cocoa

RACSignal for an NSArray of objects

限于喜欢 提交于 2019-12-03 03:47:16
I have an NSArray of ViewModel objects on my ViewController: @property (nonatomic, strong) NSArray *viewModels; A ViewModel object looks something like this: @interface ViewModel : NSObject @property (nonatomic) BOOL isSelected; @end I am trying to create a RACSignal for the enabledSignal on a RACCommand's init method: - (id)initWithEnabled:(RACSignal *)enabledSignal signalBlock:(RACSignal * (^)(id input))signalBlock This signal will tell the Command to be enabled if there are either 0 viewModel objects selected or if the number of viewModels selected is equal to the total count of the

rac_signalForSelector: needs empty implementation

对着背影说爱祢 提交于 2019-12-03 03:21:48
I have a class that implements the UICollectionViewDelegate protocol. I'm using rac_signalForSelector: to register selection like this: [self rac_signalForSelector:@selector(collectionView:didSelectItemAtIndexPath:)] but it only fires if I leave in an empty implementation of collectionView:didSelectItemAtIndexPath: like this: - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { // Empty } I tried with rac_signalForSelector:fromProtocol: as well without luck. I'm using Reactive Cocoa 2.2.4 Thanks, Mikkel Make sure you call -rac

When to use RACReplaySubject vs. RACMulticastConnection?

跟風遠走 提交于 2019-12-03 03:18:31
问题 Using ReactiveCocoa, there seem to be two ways to have subscribers receive the same values from a signal, rather than re-triggering whatever operation generates those values: Via RACReplaySubject or RACMulticastConnection. Here are the header docs for RACReplaySubject: A replay subject saves the values it is sent (up to its defined capacity) and resends those to new subscribers. It will also replay an error or completion. And for RACMulticastConnection: A multicast connection encapsulates the

How to implement a basic UITextField input + UIButton action scenario using ReactiveCocoa 3?

时光毁灭记忆、已成空白 提交于 2019-12-03 01:27:06
I'm a Swift and ReactiveCocoa noob at the same time. Using MVVM and Reactive Cocoa v3.0-beta.4 framework, I'd like to implement this setup, to learn the basics of the new RAC 3 framework. I have a text field and I want the text input to contain more than 3 letters, for validation. If the text passes the validation, the button underneath should be enabled. When the button receives the touch down event, I want to trigger an action using the view model's property. Since there are very few resources about RAC 3.0 beta at the moment, I implemented the following by reading the QAs on the framework's

Approach to Reactifying delegate methods with side effects

怎甘沉沦 提交于 2019-12-03 00:31:53
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 fade the navigationBar back in and reset the contentInset in an animation Here is the current code that

Meaning of Objective-C macros prefixed with an at (@) symbol

柔情痞子 提交于 2019-12-02 22:51:36
The ReactiveCocoa framework makes use of weakify and strongify macros, both of which are preceded by an '@' symbol. Here's an example (From this file ). - (RACSignal *)rac_textSignal { @weakify(self); return [[[[RACSignal ... ]; } What is the significance of the at symbol that is a prefix to the macro name? (NOTE: I have checked the macro, and it is called 'weakify', not '@weakify', so it isn't just the macro name!). The macro itself is defined here: https://github.com/jspahrsummers/libextobjc/blob/master/extobjc/EXTScope.h#L45 There is no special meaning to macros starting with an @ . This is

Chaining asynchronous operations from an array of objects with ReactiveCocoa

◇◆丶佛笑我妖孽 提交于 2019-12-02 20:51:58
I have an array of entities and I want to perform asynchronous operations on the entities. The operations should be chained and run in the same order with the entities in the array. I'm new to RAC. How to do that in RAC? First, you'll need a wrapper method that performs your async operation, which will return a signal. Let's assume the async operation operation takes a completion block. From the sounds of it, you don't care about the values, you want the side effects, in which case the signal does not send values, it only completes. - (RACSignal *)asyncOperation { return [RACSignal

How to use Reactive Cocoa with notifications

别等时光非礼了梦想. 提交于 2019-12-02 18:40:18
How can I create a signal out of a notification name? For example, I want to go from: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidChange:) name:kTTCurrentUserLoggedOffNotification object:nil]; to something like: [signalForName(kTTCurrentUserLoggedOffNotification) subscribeNext:^(id x){ ... }]; -[NSNotificationCenter rac_addObserverForName:object:] returns an infinite signal. You can subscribe to it like this Objective-c [[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIApplicationDidEnterBackgroundNotification object:nil] takeUntil:[self rac

When to use RACReplaySubject vs. RACMulticastConnection?

别说谁变了你拦得住时间么 提交于 2019-12-02 16:49:24
Using ReactiveCocoa , there seem to be two ways to have subscribers receive the same values from a signal, rather than re-triggering whatever operation generates those values: Via RACReplaySubject or RACMulticastConnection. Here are the header docs for RACReplaySubject: A replay subject saves the values it is sent (up to its defined capacity) and resends those to new subscribers. It will also replay an error or completion. And for RACMulticastConnection: A multicast connection encapsulates the idea of sharing one subscription to a signal to many subscribers. This is most often needed if the

Difference between catch: and subscribeError:

耗尽温柔 提交于 2019-12-02 16:19:26
In ReactiveCocoa , what's the difference between the subscribeError: method vs. catch: ? Why would you want to return a signal in catch: ? -subscribeError: actually subscribes: this is the end of the line. Whereas -catch: simply transforms a signal into a new signal (and doesn't actually subscribe). Think of the signal like a program. When you -subscribeError: , you are telling the computer "I want to run this program, but I only want to hear back from you if it errors out." When you -catch: , you are saying "I've got this program that may throw an error, and I want to make a new one based on