Заменить
let cities = try JSONDecoder().decode([city].self, from: data!)
на
let root = try JSONDecoder().decode(Root.self, from: data!)
let cities = root.data
cities.forEach {
print($0.id)
}
struct Root: Codable {
let status: String
let data: [City]
}
struct City: Codable {
let id, cityName, cityImage: String // you can use snake case also
enum CodingKeys: String, CodingKey {
case id
case cityName = "city_name"
case cityImage = "city_image"
}
}
Ваш корень - это словарь, а не массив