diff --git a/ProjectClock/AddAlarmViewController.swift b/ProjectClock/AddAlarmViewController.swift index fac87e0..a717a10 100644 --- a/ProjectClock/AddAlarmViewController.swift +++ b/ProjectClock/AddAlarmViewController.swift @@ -130,17 +130,6 @@ class AddAlarmViewController: UIViewController let (h, m, _) = timePicker.date.getHMS() var oldAlarm: Alarm? = nil - // Check if editing alarm - if (editFlag) - { - oldAlarm = removeCurrentAlarm() - } // Check for existing alarm - else if ((Alarms.fromLocal().list.contains { $0.hour == h && $0.minute == m })) - { - msg("Nope", "You already have an alarm at " + String(format: "%i:%02i", h, m)) - return - } - // Create the alarm let alarm = Alarm(hour: h, minute: m, text: alarmNameTextField.text ?? "Alarm", @@ -152,6 +141,21 @@ class AddAlarmViewController: UIViewController if repeatWeekdaysSwitch.isOn { (1...5).forEach { alarm.repeats[$0] = true } } if repeatWeekendsSwitch.isOn { [0, 6].forEach { alarm.repeats[$0] = true } } + // Check if editing alarm + if (editFlag) + { + oldAlarm = removeCurrentAlarm() + } // Check for existing alarm + else + { + for a in Alarms.fromLocal().list { + if a == alarm { + msg("Sorry", "An identical or similar alarm already exists, please try again") + return + } + } + } + // 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 5614005..84fa812 100644 --- a/ProjectClock/Models.swift +++ b/ProjectClock/Models.swift @@ -64,8 +64,7 @@ class Alarm: Codable, Equatable { static func == (lhs: Alarm, rhs: Alarm) -> Bool { return lhs.hour == rhs.hour && lhs.minute == rhs.minute && lhs.text == rhs.text && - lhs.alarmTone == rhs.alarmTone && lhs.notificationID == rhs.notificationID && - lhs.repeats == rhs.repeats + lhs.alarmTone == rhs.alarmTone && lhs.repeats == rhs.repeats } var enabled: Bool