This is Combine publisher stream that i am creating to get input from text and making web api request. But the problem i am facing is changing the request object’s properties (any mutable property in request object).
Below given code works fine but if i hold the request object like var requestWeather = WeatherRequest(query:city)
and then pass it to context.requestExecutor.executeRequest(request: requestWeather)
compiler gives an error. Please help me understand how can in make change to request object before passing it to executeRequest.
anyCancellable = NotificationCenter.default.publisher(for: UITextField.textDidChangeNotification, object: self.placeNameField).compactMap { notification in
(notification.object as? UITextField)?.text?.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
}.debounce(for: .milliseconds(500), scheduler: RunLoop.main).flatMap { [self] city in
return (context.requestExecutor.executeRequest(request: WeatherRequest(query: city)) ).catch { error in
Just(Place(id: 0, name: "", coordinate: Coordinate.init(lat: 0, lon: 0), weatherValues: Weather.init(temp: nil, humidity: nil, pressure: nil)))
}.map({ $0})
}.sink { object in
print("Returned data - \(object)")
}