Search code examples
objective-cclosuresblockswiftreactive-cocoa

Converting Reactive Cocoa doNext^ to Swift


I have the following Obj-C method:

- (RACSignal *)updateCurrentConditions {
    return [[self.client fetchCurrent:self.coordinate] doNext:^(WXCondition *condition) {
        self.currentCondition = condition;
    }];
}

I'm trying to figure out how to convert it into Swift, except I'm not sure how to return it properly.

How would I go about doing:

[[self.client fetchCurrent:self.coordinate] doNext:^(WXCondition *condition) {}];?

func updateCurrentConditions() -> RACSignal {
    return client.fetchCurrent(coordinate: coordinate) {
        currentCondition = condition
    }
}

Here is a link to ReactiveCocoa and information regarding -doNext:


Solution

  • You can try this:

    func updateCurrentConditions() -> RACSignal {
      let fetchSignal = client.fetchCurrent(coordinate: coordinate)
      return fetchSignal.doNext(block: {condition: WXCondition? -> Void in
        let wxCondition = condition as WXCondition
        currentCondition = wxCondition
      })
    }