Hello
I am getting a lot of errors in ForEach and I don't know why at all.
Here is the code:
The error is at line 12
Thank you
I am getting a lot of errors in ForEach and I don't know why at all.
Here is the code:
The error is at line 12
Code Block import SwiftUI import Combine struct ContentView: View { @EnvironmentObject var networkController: NetworkControllerItalia var body: some View { Form{ TextField("Input city name", text: $networkController.cityName) Section { ForEach(networkController.users.weather, id: \.self){ user in } } } } } class NetworkControllerItalia: ObservableObject { private var can: AnyCancellable? @Published var cityName: String = "" @Published var users = [UserItalia(weather: Weather())] init(cityName: String) { self.cityName = cityName let url = URL(string: "http://api.openweathermap.org/data/2.5/weather?q=\(cityName)&appid=")! self.can = URLSession.shared.dataTaskPublisher(for: url) .map { $0.data } .decode(type: [UserItalia].self, decoder: JSONDecoder()) .eraseToAnyPublisher() .receive(on: DispatchQueue.main) .sink(receiveCompletion: {completion in print(completion) }, receiveValue: { users in self.users = users }) } } struct UserItalia: Decodable, Hashable{ var weather: Weather } struct Weather: Decodable, Hashable { var main: String? }
Thank you