February 12, 2014

Reactive Cocoa

Update: More reasoning here.

I was reading a Big Nerd Ranch article on ReactiveCocoa, and I still don’t quite¬†get it.

Lifting a simple example from their post, are we really down to say that

- (void)viewDidLoad {
    [super viewDidLoad];
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    @weakify(self);
    [[refreshControl rac_signalForControlEvents:UIControlEventValueChanged] subscribeNext:^(UIRefreshControl *refreshControl) {
            @strongify(self);
            [topQuestionsSignal subscribeNext:^(NSArray *questions){
                [self loadQuestions:questions];
            } error:^(NSError *error) {
                [self displayError:error.localizedDescription title:@"An error occurred"];
                [refreshControl endRefreshing];
            } completed:^{
                [refreshControl endRefreshing];
            }];
        }];
    self.refreshControl = refreshControl;
}

is better code than:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.refreshControl = [[UIRefreshControl alloc] init];
    [self.refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
}

- (void)refresh:(UIRefreshControl*)refreshControl {
    [[RSOWebServices sharedWebServices] fetchQuestionsWithDelegate:self];
}

- (void)webService:(RSOWebServices*)webService fetchedQuestions:(NSArray*)questions {
    [self loadQuestions:questions];
    [refreshControl endRefreshing];
}

- (void)webService:(RSOWebServices*)webService failedWithError:(NSError*)error {
    [self displayError:error.localizedDescription title:@"An error occurred"];
    [refreshControl endRefreshing];
}

It seems that people are looking for something new, rather than something good.