[F] Make oneTime a computed property
This commit is contained in:
@@ -62,7 +62,6 @@ class AddAlarmViewController: UIViewController
|
|||||||
(0...6).forEach { alarm.repeats[$0] = false }
|
(0...6).forEach { alarm.repeats[$0] = false }
|
||||||
if repeatWeekdaysSwitch.isOn { (1...5).forEach { alarm.repeats[$0] = true } }
|
if repeatWeekdaysSwitch.isOn { (1...5).forEach { alarm.repeats[$0] = true } }
|
||||||
if repeatWeekendsSwitch.isOn { [0, 6].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
|
// Add the alarm to the list and save the list
|
||||||
Alarms.fromLocal().apply { $0.list.append(alarm) }.localSave();
|
Alarms.fromLocal().apply { $0.list.append(alarm) }.localSave();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import Foundation
|
|||||||
|
|
||||||
struct User: Codable
|
struct User: Codable
|
||||||
{
|
{
|
||||||
var id: Int
|
var id: String
|
||||||
var name: String
|
var name: String
|
||||||
var email: String
|
var email: String
|
||||||
var pass: String
|
var pass: String
|
||||||
@@ -48,9 +48,6 @@ class Alarm: Codable
|
|||||||
/// What days does it repeat (Sun, Mon, Tue, Wed, Thu, Fri, Sat)
|
/// What days does it repeat (Sun, Mon, Tue, Wed, Thu, Fri, Sat)
|
||||||
var repeats: [Bool]
|
var repeats: [Bool]
|
||||||
|
|
||||||
/// Does it automatically disable after activating once
|
|
||||||
var oneTime: Bool
|
|
||||||
|
|
||||||
/// When is the last time that the alarm went off
|
/// When is the last time that the alarm went off
|
||||||
var lastActivate: Date
|
var lastActivate: Date
|
||||||
|
|
||||||
@@ -58,7 +55,7 @@ class Alarm: Codable
|
|||||||
init(enabled: Bool = true,
|
init(enabled: Bool = true,
|
||||||
hour: Int, minute: Int, text: String, wakeMethod: WVM,
|
hour: Int, minute: Int, text: String, wakeMethod: WVM,
|
||||||
repeats: [Bool] = [false, true, true, true, true, true, false],
|
repeats: [Bool] = [false, true, true, true, true, true, false],
|
||||||
oneTime: Bool = false, lastActivate: Date = Date()
|
lastActivate: Date = Date()
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
@@ -67,10 +64,12 @@ class Alarm: Codable
|
|||||||
self.text = text
|
self.text = text
|
||||||
self.wakeMethod = wakeMethod
|
self.wakeMethod = wakeMethod
|
||||||
self.repeats = repeats
|
self.repeats = repeats
|
||||||
self.oneTime = oneTime
|
|
||||||
self.lastActivate = lastActivate
|
self.lastActivate = lastActivate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Does it automatically disable after activating once
|
||||||
|
var oneTime: Bool { repeats.allSatisfy { !$0 } }
|
||||||
|
|
||||||
/// When should the alarm activate next since lastActivate?
|
/// When should the alarm activate next since lastActivate?
|
||||||
var nextActivate: Date?
|
var nextActivate: Date?
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class TestingViewController: UIViewController
|
|||||||
@IBAction func addAlarm(_ sender: Any)
|
@IBAction func addAlarm(_ sender: Any)
|
||||||
{
|
{
|
||||||
let (h, m, _) = Date().getHMS()
|
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)
|
@IBAction func deleteAlarm(_ sender: Any)
|
||||||
|
|||||||
Reference in New Issue
Block a user