diff --git a/ProjectClock/AddAlarmViewController.swift b/ProjectClock/AddAlarmViewController.swift index 172b456..ad21867 100644 --- a/ProjectClock/AddAlarmViewController.swift +++ b/ProjectClock/AddAlarmViewController.swift @@ -62,7 +62,6 @@ class AddAlarmViewController: UIViewController (0...6).forEach { alarm.repeats[$0] = false } if repeatWeekdaysSwitch.isOn { (1...5).forEach { alarm.repeats[$0] = true } } if repeatWeekendsSwitch.isOn { [0, 6].forEach { alarm.repeats[$0] = true } } - if (alarm.repeats.allSatisfy { !$0 }) { alarm.oneTime = true } // Add the alarm to the list and save the list Alarms.fromLocal().apply { $0.list.append(alarm) }.localSave(); diff --git a/ProjectClock/Models.swift b/ProjectClock/Models.swift index 7792d6f..b144d29 100644 --- a/ProjectClock/Models.swift +++ b/ProjectClock/Models.swift @@ -9,7 +9,7 @@ import Foundation struct User: Codable { - var id: Int + var id: String var name: String var email: String var pass: String @@ -48,9 +48,6 @@ class Alarm: Codable /// What days does it repeat (Sun, Mon, Tue, Wed, Thu, Fri, Sat) var repeats: [Bool] - /// Does it automatically disable after activating once - var oneTime: Bool - /// When is the last time that the alarm went off var lastActivate: Date @@ -58,7 +55,7 @@ class Alarm: Codable init(enabled: Bool = true, hour: Int, minute: Int, text: String, wakeMethod: WVM, repeats: [Bool] = [false, true, true, true, true, true, false], - oneTime: Bool = false, lastActivate: Date = Date() + lastActivate: Date = Date() ) { self.enabled = enabled @@ -67,10 +64,12 @@ class Alarm: Codable self.text = text self.wakeMethod = wakeMethod self.repeats = repeats - self.oneTime = oneTime self.lastActivate = lastActivate } + /// Does it automatically disable after activating once + var oneTime: Bool { repeats.allSatisfy { !$0 } } + /// When should the alarm activate next since lastActivate? var nextActivate: Date? { diff --git a/ProjectClock/TestingViewController.swift b/ProjectClock/TestingViewController.swift index a6251b3..c2fbcf5 100644 --- a/ProjectClock/TestingViewController.swift +++ b/ProjectClock/TestingViewController.swift @@ -58,7 +58,7 @@ class TestingViewController: UIViewController @IBAction func addAlarm(_ sender: Any) { let (h, m, _) = Date().getHMS() - Alarms.fromLocal().apply { $0.list.append(Alarm(hour: h, minute: m, text: "Test alarm - \(h * m)", wakeMethod: wvms[1], repeats: [true, true, true, true, true, true, true], oneTime: true, lastActivate: Date().added(.minute, -1))) }.localSave() + Alarms.fromLocal().apply { $0.list.append(Alarm(hour: h, minute: m, text: "Test alarm - \(h * m)", wakeMethod: wvms[1], repeats: [true, true, true, true, true, true, true], lastActivate: Date().added(.minute, -1))) }.localSave() } @IBAction func deleteAlarm(_ sender: Any)