From 36f6abeea4b1931ba43a4f59a2826c418a8f8a31 Mon Sep 17 00:00:00 2001 From: cediackermann Date: Mon, 15 Jun 2026 09:56:36 +0200 Subject: [PATCH] add fifth one --- Sources/Aufgabe 5/BUILD.bazel | 10 ++++++++++ Sources/Aufgabe 5/main.swift | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Sources/Aufgabe 5/BUILD.bazel create mode 100644 Sources/Aufgabe 5/main.swift diff --git a/Sources/Aufgabe 5/BUILD.bazel b/Sources/Aufgabe 5/BUILD.bazel new file mode 100644 index 0000000..31fc7f8 --- /dev/null +++ b/Sources/Aufgabe 5/BUILD.bazel @@ -0,0 +1,10 @@ +load("@rules_swift//swift:swift.bzl", "swift_binary") + +# Per-directory BUILD: define targets where their sources live, then reference +# them by label (e.g. //Sources/Aufgabe 5:Aufgabe5) from elsewhere to keep the +# top-level BUILD.bazel uncluttered. +swift_binary( + name = "Aufgabe5", + srcs = ["main.swift"], + visibility = ["//visibility:public"], +) diff --git a/Sources/Aufgabe 5/main.swift b/Sources/Aufgabe 5/main.swift new file mode 100644 index 0000000..b8610a5 --- /dev/null +++ b/Sources/Aufgabe 5/main.swift @@ -0,0 +1,29 @@ +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) +}