ios – unable to map model from one type to aother with Combine in Swift


I have following code in Repository:

public final class TimeTableRepository: TimeTableRepositoryProtocol {
    private let timeTableRemoteDataSource: TimeTableRemoteDataSource
    
    init(timeTableRemoteDataSource: TimeTableRemoteDataSource) {
        self.timeTableRemoteDataSource = timeTableRemoteDataSource
    }
    
    func getTimeTable() -> AnyPublisher<[TimeTableEntity]?, Error> {
        timeTableRemoteDataSource.getTimeTable().flatMap { return $0.toDomain() }
    }
}

I am getting following error when I try to map the TimeTableModel to TimeTableEntity:

  1. ‘flatMap(maxPublishers:_:)’ produces ‘Publishers.FlatMap<[TimeTableEntity]?, AnyPublisher<TimetableModel,
    any Error>>’, not the expected contextual result type
    ‘AnyPublisher<[TimeTableEntity]?, any Error>’ (Combine.Publisher)

toDomain function:

extension TimetableModel {
    func toDomain() -> [TimeTableEntity]? {
        timetable.departures.map{ TimeTableEntity(lineDirection: $0.lineDirection ?? "", ThroughStations: $0.throughTheStations ?? "", timestamp: $0.datetime.timestamp, timezone: $0.datetime.tz) }
    }
}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img