reactive-cocoa

rac_signalForSelector: needs empty implementation

﹥>﹥吖頭↗ 提交于 2019-12-03 14:15:46
问题 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:

RACSignal for an NSArray of objects

对着背影说爱祢 提交于 2019-12-03 13:51:04
问题 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

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

别来无恙 提交于 2019-12-03 10:08:32
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? [[RACAble(self.test) take:1] subscribeNext:^(id x) { NSLog(@"signal fired!"); }]; That might be helpful especially when you create nested subscriptions: RACDisposable *subscription = [RACObserve(self, test) subscribeNext:^(id x) {

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

岁酱吖の 提交于 2019-12-03 09:49:38
问题 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

Can/How Should I replace my KVO stuff with RC3?

我是研究僧i 提交于 2019-12-03 08:26:18
I'm trying to port an objc app which uses Facebook's KVOController, to Swift. I've been encouraged to look at RC3 as an alternate and more Swiftish approach. I've read some blogs and I'm encouraged to give this a try. But much of the docs and blogs seem to concentrate on sockets and timers as examples. So I have two simple questions right now: 1) Given an objc fragment like: [self.KVOController observe: self.site keyPath: @"programs" options: NSKeyValueObservingOptionInitial block:^(id observer, id object, NSDictionary *change) { [self.tableView reloadData]; }]; What is the simple way to

Why the signal is called twice in ReactiveCocoa?

你说的曾经没有我的故事 提交于 2019-12-03 07:44:38
I'm implementing my first code with https://github.com/ReactiveCocoa/ReactiveCocoa . Is for login a user. The line [subscriber sendNext:user]; is called twice, but I expect to be only one. And the map is not called at all (so autologin is never called) This is my implementation: -(RACSignal *) login:(NSString *)email pwd:(NSString *)pwd { DDLogInfo(@"Login user %@", email); RACSignal *login = [RACSignal createSignal:^ RACDisposable *(id<RACSubscriber> subscriber) { [PFUser logInWithUsernameInBackground:email password:pwd block:^(PFUser *user, NSError *error) { if (error) { [subscriber

Chaining asynchronous operations from an array of objects with ReactiveCocoa

百般思念 提交于 2019-12-03 06:18:54
问题 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? 回答1: 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

ReactiveSwift Simple Example

若如初见. 提交于 2019-12-03 06:05:38
I've read the documentation , gone through their wonderful Playground example, searched S.O., and reached the extent of my google-fu , but I cannot for the life of me wrap my head around how to use ReactiveSwift. Given the following.... class SomeModel { var mapType: MKMapType = .standard var selectedAnnotation: MKAnnotation? var annotations = [MKAnnotation]() var enableRouteButton = false // The rest of the implementation... } class SomeViewController: UIViewController { let model: SomeModel let mapView = MKMapView(frame: .zero) // It's position is set elsewhere @IBOutlet var routeButton:

ReactiveCocoa example with NSMutableArray push/pop?

橙三吉。 提交于 2019-12-03 05:49:30
问题 Could someone provide a one-line example of using ReactiveCocoa abstractions to achieve something like this: // pseudo-code NSMutableArray *array = @[[] mutableCopy]; RACSignal *newValue = RACAbleWithStart(array); // get whole array or maybe just added/removed element on push/pop [newValue subscribeNext:^(NSArray *x) { // x is whole array }] [newValue subscribeNext:^(id x) { // x is new value }] [newValue subscribeNext:^(id x) { // x is removed value }] I see that some extensions for NSArray

Difference between catch: and subscribeError:

99封情书 提交于 2019-12-03 04:00:41
问题 In ReactiveCocoa, what's the difference between the subscribeError: method vs. catch: ? Why would you want to return a signal in catch: ? 回答1: -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