FAQ Database Discussion Community


RACCommand compilation failure on swift 1.2

ios,swift,compiler-errors,reactive-cocoa
I have a login button with a RACCommand assigned to it to perform a login request and return me a user object. I want to handle the errors from the buttons signal errors. loginButton.rac_command.executionSignals.flatten() .logAll() .subscribeNext { (_:AnyObject!) -> Void in println("Sent next") } so i added the doError block...

ReactiveCocoa - Subscribe to the second signal, if the first completes with no value

reactive-cocoa
Imagine I have two signals: a cheap one and an expensive one: RACSignal *localSignal; // Cheap signal. Sends object without network request // if possible, otherwise completes immediately. RACSingal *networkSignal; // Expensive one. Always sends data, // but requires expensive network operation. Now I want to create a signal, which...

UISearchResultsUpdating w/ ReactiveCocoa

ios,swift,reactive-cocoa
I'm building a UISearchController in which users will type a username, and the application will fetch results from a web service. I want to throttle the requests to reduce network calls while the user is typing. Using ReactiveCocoa how would one go about implementing this? class SearchResultsUpdater: NSObject, UISearchResultsUpdating {...

ReactiveCocoa : Chain a signal with a repeating signal

ios,reactive-programming,reactive-cocoa,racsignal
Using ReactiveCocoa, how can I chain a signal from a repeating one? I would like to do something like this: Every 5 seconds, I run a network request. For this purpose, I created a repeating signal RACSignal *each5SecondSignal = [[[RACSignal interval:5 onScheduler:[RACScheduler mainThreadScheduler]] take:1] concat:[RACSignal 5 onScheduler:[RACScheduler mainThreadScheduler]]]; and a...

Reactive Cocoa diferences between KVC and instance object

ios,key-value-observing,reactive-cocoa,key-value-coding,kvc
I use this code to subscribe events with my mutable array: [RACObserve(self, marray) subscribeNext:^.... I am new in RAC and I don't understand why for example if I use: NSMutableArray *keyValueCodingArray = [self mutableArrayValueForKey:@"marray"]; [keyValueCodingArray addObject:@"string"]; everything works ok and if I add something to my keyValueCodingArray which is my...

Reactive Cocoa: subscribe only to new values

ios,cocoa,reactive-cocoa
I'm new to Reactive Cocoa. What I'm trying to achieve is get notified every time property value changes. However, I don't want to get notified when property is set to the same value. Here's some code: self.testProperty = 0; [[RACObserve(self, self.testProperty) skip:1] subscribeNext:^(id x) { NSLog(@"Did Change: %@", x); }];...

ReactiveCocoa ignore nil in Swift

swift,reactive-cocoa
I'm using ReactiveCocoa in many places around my app. I've build a check to skip nil values as followed: func subscribeNextAs<T>(nextClosure:(T) -> ()) -> RACDisposable { return self.subscribeNext { (next: AnyObject!) -> () in self.errorLogCastNext(next, withClosure: nextClosure) } } private func errorLogCastNext<T>(next:AnyObject!, withClosure nextClosure:(T) -> ()){ if let nextAsT =...

Objc-C: RACObserve rapidly changing values (RACSignal for AFHTTPRequestOperation)

ios,objective-c,reactive-cocoa,afhttprequestoperation
I am using reactive cocoa to create download file from server. I have a DownloadMapFileOperation.m file with a progress property (progress value, currentBytes, totalBytes). It changes very rapidly in my next RACSignal method and float progress (it's unnecesarry, but @property (nonatomic, strong, readwrite) NSMutableDictionary *progressDictionary; @property (nonatomic, assign, readwrite) float...

What is the difference between RACSequence and RACSignal

ios,functional-programming,reactive-cocoa
Maybe I'm totally missing this but according to the documentation on ReactiveCocoa on their types, RACSequences are signals. However. I see examples where you have code like this: RACSignal *letters = [@"A B C D E F G H I" componentsSeparatedByString:@" "].rac_sequence.signal; // Outputs: A B C D E F...

How to prevent a signal to send a next event before subsequent asynchronous calls are completed?

ios,objective-c,reactive-cocoa
I am willing to prevent a RAC signal to send a next event message before some subsequents calls are completed. Here is an example of how i have proceed so far: - (RACSignal *) fetchNearbyDatasForLocation: (CLLocationCoordinate2D)coordinate { RACSignal* finalSignal = [RACSignal createSignal:^ RACDisposable * (id<RACSubscriber> subscriber) { [subscriber sendNext:self.rawDatas]; [subscriber...

How to use sendError in ReactiveCocoa

ios,reactive-cocoa
I am new to reactive Cocoa and like it much that far. I created a register page. If the username and password are valid I enable the register Button. For the login button I did the following: [[[[self.registerButton rac_signalForControlEvents:UIControlEventTouchUpInside] doNext:^(id x) { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; self.registerButton.enabled = NO; }] flattenMap:^RACStream...

ReactiveCocoa: How do you bind a button's title to a text property?

ios,reactive-cocoa
I've got a UIButton whose title for state normal/highlighted should keep synced with a property of its container object. How can I bind button title for specific state with a string property? Edit: I know that using RACObserve and change the button title in subcribeNext block is a solution. I'm...

How to make basic bindings in ReactiveCocoa 3

swift,reactive-cocoa,reactive-cocoa-3
I've been reading up on ReactiveCocoa v3 lately and I'm struggling with just setting up basic stuff. I've already read the changelog, the tests, the few SO questions and the articles by Colin Eberhardt on the subject. However, I'm still missing examples on basic bindings. Let's say I have an...

RACSignal and an array of view models, is there a more reactive way?

ios,objective-c,mvvm,reactive-cocoa
I use UITableViewController to show discovered devices. They are obtained from SDDeviceBrowser, which scans for them constantly and calls its delegate method each time a new device is found. I created a RACSignal like this: @implementation SDDeviceBrowser (RAC) - (RACSignal*)rac_newDeviceSignal { return [self rac_signalForSelector:@selector(deviceBrowserDidFindNewDevice:) fromProtocol:@protocol(SDDeviceBrowserDelegate)]; } @end I use MVVM...

What is wrong with this simple `-flattenMap` ReactiveCocoa code?

objective-c,reactive-cocoa
After reading the README on -flattenMap several times I still can't figure out why this code isn't executing as expected. I should think that the code inside the block would be run twice but it's not getting hit at all. Am I missing something really silly? (I'm using v2.4.7) I...

Property vs RACSignal

reactive-cocoa
I just started with ReactiveCocoa (and FRP for that matter) and every time I start refactoring my code to be more RAC-based, I ask myself: when should I create a property or a RACSignal? For example, if I have a ViewModel that does some checking to see if a button...

Removing nested subscribeNext in reactive pipeline

ios,objective-c,reactive-programming,reactive-cocoa
I am trying to construct a reactive pipeline where a change in some input signals will trigger off an asynchronous web api request. But I do not need to perform anything in the subscribeNext block of the web api. This is how it looks: RACSignal *inputChanged = [[RACSignal merge:@[ RACObserve(self,...

Auto-repeating count down timer in ReactiveCocoa

ios,objective-c,timer,reactive-cocoa
I'm new to ReactiveCocoa and there is a problem I couldn't yet find a way to solve. I have a network request in my app which returns data to be encoded in a QR code that will be valid for only 30 seconds. The network request returns a RACSignal and...

ReactiveCocoa: rac_keywordify macros. For what purpose rac_keywordify is actually need?

macros,reactive-cocoa
In ReactiveCocoa there are two macros which are using in conjunction. #define weakify(...) \ rac_keywordify \ metamacro_foreach_cxt(rac_weakify_,, __weak, __VA_ARGS__) #define strongify(...) \ rac_keywordify \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wshadow\"") \ metamacro_foreach(rac_strongify_,, __VA_ARGS__) \ _Pragma("clang diagnostic pop") #if DEBUG #define rac_keywordify autoreleasepool {} #else #define rac_keywordify try {}...

How can I convert “SignalProducer” to “SignalProducer” of ReactiveCocoa 3?

ios,swift,reactive-cocoa,reactive-cocoa-3
I tried creating an instance of Action<AnyObject?, Bool, NSError> of ReactiveCocoa 3. let action: Action<AnyObject?, Bool, NSError> = Action { _ in if self.flag { return self.fooSignalProducer // SignalProducer<Bool, NoError> } else { return self.barSignalProducer // SignalProducer<Bool, NSError> } } This code isn't able to compile with error 'SignalProducer<Bool, NoError>'...

How can I subscribe to a one-time signal and conditionally initiate a secondary signal without having the original signal fired twice?

ios,objective-c,reactive-programming,reactive-cocoa
I would like to subscribe to a signal of one web operation and have it conditionally initiate a secondary web operation. The code I have put together looks a little like this: RACSignal *asyncWebAPI = [self asyncWebAPI]; @weakify(self) [asyncWebAPI subscribeNext:^(RACTuple *tuple) { @strongify(self) NSArray *foo = tuple.first; [self.bar addObjects:foo]; self.baz...

Combine and reduce but wait for each signal to complete before subscribing to next one

ios,objective-c,reactive-cocoa
I have 2 network signals and the first one needs to complete before the next one starts because I need to send an accessToken for the second request and I obtain that in the first request. Then I want to reduce the values from each step into a single object....

Should I rebind models in ReactiveCocoa MVVM?

objective-c,reactive-cocoa
I have started setting up my view models so they automatically unbind/bind themselves to any model they represent. I'm relatively new to ReactiveCocoa and want to know if what I'm doing is bad/good practice or if there's a better way to do it. For example, if I have a view...

How to Convert NSError SignalProducer to NoError SignalProducer in ReactiveCocoa (Swift)

ios,swift,reactive-cocoa,reactive-cocoa-3
I have a model with a MutableProperty<Bool> and I have a UIButton (ctaTopButton) that should flip that property when it's pressed, for example, on click true becomes false and vice versa. I have it setup this way: let producer = ctaTopButton.rac_signalForControlEvents(UIControlEvents.TouchUpInside).toSignalProducer() |> map {value in !self.model.enabled.value} // model.enabled <~ producer...

How to create a looping RACSignal with RACScheduler

swift,reactive-cocoa,racsignal
Is there a way to create a scheduled RACSignal that emits value every interval of time ? I'm wondering if there is a way other than creating a dispatch timer ? or some kind of for loop....

ReactiveCocoa - How to get one item at a time from RACSequence?

reactive-cocoa,racsequence
I keep reading that RACSequences are "pull-driven". Can someone explain to me how to "pull" values out of a sequence on demand? Say I have an array that I have turned into a signal. Then say there is another signal and when a value is sent on it, I want...

How to update SceneKit nodes to 'automatically' reflect underlying model?

swift,cocoa-touch,scenekit,reactive-cocoa
What is the most sensible way of locating, updating, and/or adding or removing SceneKit nodes that correspond to an underlying model when that model is updated? I'm not sure how best to word this question, so it's probably easier to have a minimal example: I have something, let's say a...

ELI5: (Reactive cocoa ) - React to a Filter returning no

ios,objective-c,reactive-cocoa
I am very new to reactive cocoa and I'm still getting my head around it. But I feel like this should be possible: Create a signal around a search for a file. (imageSearchSignal) If the the image isn't found use the download signal and download it. (downloadImageSignal) So what I'm...

RACObserve not working

ios,reactive-cocoa
I'm trying to observe a property in my ViewModel, and then update a label with it's value using ReactiveCocoa, but it's not updating. Here's what I got: ViewModel var amount: NSDecimalNumber ViewController RAC(self.amountLabel, "text") <~ RACObserve(self.viewModel, "amount").map({ (value) -> AnyObject! in let numberFormatter = NSNumberFormatter() numberFormatter.numberStyle = .CurrencyStyle return numberFormatter.stringFromNumber(value...

ReactiveCocoa subscribeNext with nil check

ios,objective-c,reactive-cocoa
Most of the times when I user subscribe next, Ill check if the value isn't nil first, like so: [[RACObserve(self.viewModel, stockViewModel.stock.imageURL) takeUntil:[self takeUntil]] subscribeNext:^(id value) { @strongify(self); //Check if not nil if (value) { //Do somthing } }]; Insted of doing this every time, Im trying to right a category...

Reactivecocoa send new value

ios,objective-c,iphone,mvvm,reactive-cocoa
I'm new to reactivecocoa and I need help. I was searching and I couldn't figure it out. Let assume that I have UIPickerView. In that pickerView there are 4 options, for each language one for example german, english, spanish, french. On selected language I need to send back abbreviation english...

ReactiveCocoa, combine two signals on button enabled

ios,objective-c,mvvm,reactive-cocoa
I'm using MVVM architecture and I have two signals: RACSignal *internetEnabledSignal = RACObserve(self.regWizardVehicleViewModel, internetConnectionEnabled); RACSignal *executingRegistrationSignal = RACObserve(self.regWizardVehicleViewModel, isExecuting); I need to combine and bind signals on button enabled property. Button needs to be disabled if there is not any connection OR when some method is executing. I was searching...

Observing mouse event in ViewModel Swift (Reactive Cocoa 3.0)

swift,mvvm,reactive-cocoa,reactive-cocoa-3
I'm trying to make a connection between my view and my viewModel using RAC 3.0. (Been reading Colin Eberhardt great tutorials on this) I want to subscribe to a Signal that fires every time func mouseUp(theEvent: NSEvent) is called. I.e. func mouseUp(theEvent:NSEvent){ //create some signal or pass a variable here...

Checking for nil model using reactive cocoa?

reactive-programming,reactive-cocoa
I was wondering what the approach for checking for nil values with reactive cocoa is. I would assume I could create a signal like so. // Turn state check into a signal to activate the rest RACSignal* modelSignal = [self checkIfModelIsValid:self.model]; [[modelSignal then:^RACSignal *{ return [self obtainImageSignal]; // Always need...

Detect if at least one property of object was modified

ios,objective-c,key-value-observing,reactive-cocoa,kvc
I have class with many strings and mutable arrays. All this objects represent form data. So if I modify textfield or add new photo to array I keep this data in my properties of object. How can I create validator that will check if some of that properties were changed....

Send error from doNext block?

ios,objective-c,design-patterns,reactive-cocoa,overcoat
I'm using ReactiveCocoa and Overcoat/Mantle/AFNetworking to fetch data and authenticate a user from a RESTful API. This is the code in the login view controller that manages the login button and textfields for credentials: @weakify(self); self.loginButton.rac_command = [[RACCommand alloc] initWithEnabled:validCredentials signalBlock:^RACSignal *(id input) { @strongify(self); return [[PFUserManager sharedManager] logInUser:self.usernameTextField.text password:self.passwordTextField.text];...

ReactiveCocoa: throttle never executes / not working

objective-c,reactive-cocoa
I try to subscribe to a signal with throttle, but it never executes. I have a UISearchController (Attention: UISearchController from iOS8, not the older UISearchDisplayController, which works quiet better and has thousands of working tutorials and examples in the web) and want to make API-Requests while the user is typing....

Signal of Signals ? Reactive Cocoa

objective-c,reactive-programming,reactive-cocoa
I am trying to understand this piece of code and why it returns a signal of signals. [[[self.signInButton rac_signalForControlEvents:UIControlEventTouchUpInside] map:^id(id x) { return [self signInSignal]; }] subscribeNext:^(id x) { NSLog(@"Sign in result: %@", x); }]; From what I understand the UIControlEventTouchupInside returns a next signal which contains the UIButton when...

How to chain signals in a proper way with Reactive Cocoa?

ios,objective-c,reactive-programming,reactive-cocoa
I'm using ReactiveCocoa in a new iOS app. I'm new to reactive programming so I'm still trying to understand what's the proper way to chain signals. Right now I have the following flow for the "login with Twitter" button. The ALTUserManager class has the following method for managing the whole...

ReactiveCocoa with MVVM

ios,mvvm,reactive-cocoa
i'm very new to this reactive programming. I'm obviously missing a link here. Ok, so in my view controller at the moment, I have - (void)viewDidLoad { [super viewDidLoad]; viewModel = [[ViewModel alloc]init]; [RACObserve(viewModel, string) subscribeNext:^(NSString* string){ NSLog(@"%@", viewModel.string); }]; // This fires the NSLog viewModel.string = @"Test12345"; // This...

RACSignal combineLatest: cannot reduce

objective-c,objective-c-blocks,reactive-cocoa
I have a horrible compile problem while trying to reduce a couple of signals. RACSignal* contactIdentifierSignal = RACObserve(self, contactIdentifier); RACSignal* displayNameSignal = RACObserve(self, displayName); RACSignal* mappedThing = [RACSignal combineLatest:@[contactIdentifierSignal, displayNameSignal] reduce:^id(NSString* identifierValue, NSString* displayNameValue){ return @([identifierValue length] > 0 && [displayNameValue length] > 0); }]; The error that I get...

RACDelegateProxy vs Common Delegate implementation

ios,delegates,reactive-cocoa
I'm studying the ReactiveCocoa(I'm not good with FRP, neither with pure functional programming) and i saw the RacDelegateProxy class that can abstract the implementation of the delegate methods with a void return value. What i didn't get well is what are the benefits of using it, when we compare with...