From 56fb9b6a3da0bbdc05656b7ddc5d0f23242514c7 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 19 Jan 2021 11:44:05 -0500 Subject: [PATCH] setData function Terrible code, but it works... With Love, Andrew Vittiglio --- ProjectClock/AlarmViewController.swift | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/ProjectClock/AlarmViewController.swift b/ProjectClock/AlarmViewController.swift index 8c28b15..9a509e5 100644 --- a/ProjectClock/AlarmViewController.swift +++ b/ProjectClock/AlarmViewController.swift @@ -61,12 +61,27 @@ class AlarmTableCell: UITableViewCell @IBOutlet weak var goingOffText: UILabel! /// Update information on the cell to information in the alarm object + //WARNING:Terrible code lies ahead! You WILL be dissapointed! But it works, and that is all that matters. + func setData(_ alarm: Alarm) { descriptionText.text = "- " + alarm.text - - if alarm.enabled, let n = alarm.nextActivate - { + ampm.text = alarm.hour<12 || alarm.hour==24 ? "AM":"PM" + time.text = alarm.minute<10 ? "\(alarm.hour)" + ":" + "0" + "\(alarm.minute)":"\(alarm.hour)" + ":" + "\(alarm.minute)" + + // displays the specific days alarm is activated + let daysDict = [0: "Mon", 1: "Tues", 2: "Wed", 3: "Thurs", 4: "Fri", 5: "Sat", 6: "Sun"] + var daysActive : [String] = [] + if alarm.oneTime {repeatText.text = "No Repeat"} + else{ + for (index, element) in alarm.repeats.enumerated(){ + if element{ + daysActive.append(daysDict[index] ?? "") + } + } + repeatText.text = daysActive.joined(separator: ", ") + } + if alarm.enabled, let n = alarm.nextActivate{ goingOffText.text = "(Going off in \(n.timeIntervalSince(Date()).str()))" } }