29 lines
1.2 KiB
Swift
29 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
let weatherData: [(city: String, description: String, temperature: Double)] = [
|
|
(city: "Zurich", description: "cloudy", temperature: 18.5),
|
|
(city: "Bern", description: "sunny", temperature: 22.1),
|
|
(city: "Geneva", description: "rainy", temperature: 15.3),
|
|
(city: "Basel", description: "sunny", temperature: 24.7),
|
|
(city: "Lucerne", description: "foggy", temperature: 11.0),
|
|
(city: "Lugano", description: "sunny", temperature: 31.2),
|
|
(city: "Lausanne", description: "cloudy", temperature: 19.8),
|
|
(city: "Chur", description: "snowing", temperature: -2.5),
|
|
(city: "Davos", description: "snowing", temperature: -5.1),
|
|
(city: "Locarno", description: "thunderstorm", temperature: 27.4),
|
|
]
|
|
|
|
func weatherStation(city: String, description: String, temperature: Double) -> (
|
|
String, String, Double
|
|
)? {
|
|
if temperature >= 20 {
|
|
let dateTimeString = Date.now.formatted(date: .abbreviated, time: .shortened)
|
|
return (description, dateTimeString, temperature)
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
for weather in weatherData {
|
|
weatherStation(city: weather.0, description: weather.1, temperature: weather.2)
|
|
}
|