Monday, November 9, 2026
HomeiOS Developmentios - Mix conversion from mannequin to viewModel provides error "Sort of...

ios – Mix conversion from mannequin to viewModel provides error “Sort of expression is ambiguous with out extra context when operating .eraseToAnyPublisher()

[ad_1]

I’m attempting to determine why the final .eraseToAnyPublisher() is giving the aforementioned error, to me it appears all the categories are effectively specified, aren’t they?

static func searchUsers(question: String) -> AnyPublisher<[UserViewModel], By no means> {
            // put together URL
            let urlString = "(baseURL)/search/customers?q=(question)"
            guard let url = URL(string: urlString) else  {
                return Simply([]).eraseToAnyPublisher()
            }
            // get deal with of native knowledge process writer
            let writer = URLSession.shared.dataTaskPublisher(for: url)
                .handleEvents(
                    receiveSubscription: { _ in
                        activityIndicatorPublisher.ship(true)
                    }, receiveCompletion: { _ in
                        activityIndicatorPublisher.ship(false)
                    }, receiveCancel: {
                        activityIndicatorPublisher.ship(false)
                    })
                .tryMap { knowledge, response -> Knowledge in
                    guard let httpResponse = response as? HTTPURLResponse,
                          httpResponse.statusCode == 200 else {
                              throw NetworkError.httpError
                          }
                    print(String(knowledge: knowledge, encoding: .utf8) ?? "")
                    return knowledge
                }
                .decode(kind: SearchUserResponse.self, decoder: JSONDecoder())
                .map { $0.gadgets }
                .flatMap({ customers in
                    var userViewModels = [UserViewModel]()
                    customers.forEach { person in
                        userViewModels.append(contentsOf: UserViewModel(with: person))
                    }
                    return userViewModels
                })
                .catch { err -> Simply<[UserViewModel]> in
                    print(err)
                    return Simply([])
                }
                .eraseToAnyPublisher() // <-- HERE IS THE ERROR
            return writer
        }

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments