I'm trying to make an iOS app that uses the OpenWeatherMap API to check the current weather, but I'm getting an error saying 'Type 'MyWeather' does not conform to protocol 'Encodable''. I am new to Swift Programming and it's probably a simple mistake. I would appreciate any help, thank you.
My code below:
struct MyWeather: Codable {
let name: String?
let location: String?
let temp: URL?
let wind: Int?
//THE NAMES OF THE JSON STUFF IN THE LINK
private enum CodingKeys: String, CodingKey {
case weather
case name
case location
case temp
case wind
//THE NAMES OF THE JSON STUFF IN THE LINK
}
}
class ViewController: UIViewController {
@IBAction func ShowWeatherInfo(_ sender: Any) {
guard let APIUrl = URL(string: "http://api.openweathermap.org/data/2.5/weather?q=Crowland&appid=APIKEY&units=Metric") else { return }
URLSession.shared.dataTask(with: APIUrl) { (data, response
, error) in
guard let data = data else { return }
do {
let decoder = JSONDecoder()
let weatherData = try decoder.decode(MyWeather.self, from: data)