reactive-cocoa

Reactive Cocoa limit a signal to only one subscriber at once

耗尽温柔 提交于 2019-12-10 21:52:14
问题 I need to model following in RAC. I have a tabBarController which will subscribe to a notification signal. Say push notification. Also say currently active view controller may also be want to subscribe to the same signal. But if any view controller subscribed to it tabBarController doesn't want to handle it. Otherwise it will handle it. Also when current visible view controller changes. It needs to delegate back the responsibility to tabController. Currently without RAC I maintain array of

Migrate from RACSignal to ReactiveSwift or RAC5

白昼怎懂夜的黑 提交于 2019-12-10 21:05:20
问题 I'm new with Swift, and that's why I'm new with Reactive Cocoa v5 or Reactive Swift. Previously I used RACSignal with RAC 2.x and I liked to do something like this: - (RACSignal *)signalForGET:(NSString *)URLString parameters:(NSDictionary *)parameters { return [RACSignal createSignal:^RACDisposable *(id <RACSubscriber> subscriber) { AFHTTPRequestOperation *op = [self GET:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { [subscriber sendNext

How can I fix my install of ReactiveCocoa (with CocoaPods)?

别来无恙 提交于 2019-12-10 20:57:09
问题 Newbie here, trying to install ReactiveCocoa 2.2.4 with CocoaPods into a project and running into errors at runtime. I have used this podspec on github. Here's my code -- MainViewController.m @interface has: @property (strong, nonatomic) NSString *testString; MainViewController.m viewDidLoad() has: self.testString = @"hello"; [RACObserve(self, testString) subscribeNext:^(NSString *newString) { NSLog(@"%@", newString); }]; self.testString = @"yellow"; This is the runtime error I get, where it

How to create custom signal in ReactiveCocoa 4?

三世轮回 提交于 2019-12-10 15:31:12
问题 I have the following setup, a GridView that consists of GridViewCell s. GridView class GridView : UIView { var gridViewCells: [GridViewCell] = [] let tapHandler: Position -> () init(frame: CGRect, tapHandler: Position -> ()) { self.tapHandler = tapHandler super.init(frame: frame) self.gridViewCells = createCells(self) addCellsToView(self.gridViewCells) } func addCellsToView(cells: [GridViewCell]) { for cell in cells { self.addSubview(cell) } } } GridViewCell class GridViewCell: UIImageView {

Reactive Cocoa 5 and ReactiveSwift network requests handling

为君一笑 提交于 2019-12-10 14:54:25
问题 I'm trying to figure out if network requests handling can be implemented suitable to my needs using ReactiveSwift and RAC5. Under topic Migrate from RACSignal to ReactiveSwift or RAC5 I was told it can be done with SignalProducer, but digging deeper into it didn't give me expected results So, I would want to have: 1. Each time text changes in textField send request (search by keyword). 2. Once user closes current ViewController, the current request should be cancelled automatically 3. Have an

MVVM with ReactiveCocoa: limit the text length of a UITextField in view model

限于喜欢 提交于 2019-12-10 12:16:12
问题 I'm adopting MVVM with ReactiveCocoa. Now I have a UITextField which I need to limit it's max text length to 100. In my view: - (void)bindViewModel { RAC(self.viewModel, text) = self.textField.rac_textSignal; [RACObserve(self.viewModel, text) subscribeNext:(NSString *text) { self.textField.text = text; }]; } In my view model - (id)init { [RACObserve(self, text) subscribeNext:^(NSString *x) { //block 1 if (x.length > maxTextLength) { x = [x substringToIndex:maxTextLength]; } }]; } But this

reactivecocoa true shouldChangeCharactersInRange textfield equivalent

好久不见. 提交于 2019-12-09 23:20:15
问题 i begin with reactiveCocoa and i have some trouble with UITextfield. i try to do a basic check on a textField to display only 4 digit. i try to follow this exemple: http://nshipster.com/reactivecocoa/ but in here, shouldChangeCharactersInRange is always true so the textfield is always updated. i tried 2 solution : [RACSignal combineLatest:@[self.pinDigitField.rac_textSignal] reduce:^(NSString *pinDigit) { NSCharacterSet *numbersOnly =[NSCharacterSet characterSetWithCharactersInString:@

Unit-testing a simple usage of RACSignal with RACSubject

对着背影说爱祢 提交于 2019-12-09 14:00:03
问题 (I may be using this in a totally incorrect manner, so feel free to challenge the premise of this post.) I have a small RACTest app (sound familiar?) that I'm trying to unit test. I'd like to test MPSTicker, one of the most ReactiveCocoa-based components. It has a signal that sends a value once per second that accumulates, iff an accumulation flag is set to YES. I added an initializer to take a custom signal for its incrementing signal, rather than being only timer-based. I wanted to unit

Remove a ReactiveCocoa signal from a control

戏子无情 提交于 2019-12-08 23:39:54
问题 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

UITextField get focus and then lose focus immediately due to return YES in textFieldShouldReturn

只谈情不闲聊 提交于 2019-12-08 03:32:54
问题 Here are my codes: - (void)viewDidLoad { [super viewDidLoad]; // passwordTextField cannot get focus after click next key due to this RAC RAC(self.loginButton, enabled) = [RACSignal combineLatest:@[self.userTextField.rac_textSignal, self.passwordTextField.rac_textSignal] reduce:^id (NSString *user, NSString *password) { if ([user length] > 0 && [password length] > 0) { return @YES; } return @NO; }]; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == self.userTextField)