Reactivecocoa: signal firing twice, distinctUntilChanged not catching duplicates

Created on 20 Dec 2013  ·  3Comments  ·  Source: ReactiveCocoa/ReactiveCocoa

Ok a tad confused here.

My viewModel has a property searchString that I verified only gets set once. However this gets fired twice, making two api calls. Never mind that it shouldn't be firing twice, but there's even a distinctUntilChanged in there that's not preventing it. If I put a breakpoint in the map, it definitely hits twice with the same value for queryString.

RACSignal *searchResultsSignal = [[[[[[[[RACObserve(self, searchString)
    ignore:nil]
    ignore:@""]
    distinctUntilChanged]
    deliverOn:[RACScheduler scheduler]]
    map:^id (NSString *queryString) {
        @strongify(self);
        TCThirdPartyAPIType type = [TCAPIIndividual thirdPartyAPITypeForAPITypeString:self.activeAPI.APITypeString];
        return [TCThirdPartyAPIHelper fetchResultsForAPIType:type withQueryString:queryString latitude:self.latitude longitude:self.longitude];
    }]
    switchToLatest]
    map:^id(TCAPIResponse *response) {
        return response.result.array;
    }] catch:^RACSignal *(NSError *error) {
        return [RACSignal return: @[]];
    }];

Forgot to mention that if I subscribe directly to RACObserve(self, searchString), and insert a breakpoint, that only catches once.

question

Most helpful comment

Your comment saved my live :D

All 3 comments

Shit. Nevermind. Subscribed to twice.

Your comment saved my live :D

I've had this problem before,i use uitextfiled,When I listen for text,the signal firing twice,beause of the uitextfiled isFirstResponder changed,when isFirstResponder is NO fired,is YES fired

Was this page helpful?
0 / 5 - 0 ratings