I'm new to Swift Combine, so having a small issue
Im trying to call two api calls, and merge the results as the second API call depends on the result from the first call.
Here is the code
return self.gameRepository.fetchGames(forUser: user.id)
.map { games -> AnyPublisher<[Game], ApiError> in
let result = games.map { gameDto -> Game in
let location = self.venueRepository.fetch(by: gameDto.siteId)
.map { $0.mapToModel() }
let game = gameDto.mapToModel(location: location)
return game
}
My error is on line 4 "let location" the compiler complains when I try and pass this through to line 5
game.mapToModel(location: location)
Cannot convert value of type 'AnyPublisher' to expected argument type Location
The fetch call signature from the repository looks like this
func fetch(by id: String) -> AnyPublisher<LocationDto, ApiError>
So it is correct, but the .map call I use on the result allows the
$0.mapToModel()
to occur, so I have locationDto object that allows me to cast to my Domain model.
Any help on how I can call these two apis together would be much appreciated.