36 lines
977 B
Swift
36 lines
977 B
Swift
//
|
|
// Item.swift
|
|
// Screaming Reminder
|
|
//
|
|
// Created by Amine Bou on 11/07/2024.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
final class Notification: CustomStringConvertible {
|
|
var reminder: Reminder
|
|
var triggers: [UNCalendarNotificationTrigger]
|
|
|
|
|
|
init(reminder: Reminder) {
|
|
self.reminder = reminder
|
|
self.triggers = getTriggersForReminder(reminder: reminder)
|
|
}
|
|
|
|
public var description: String { return "\(reminder) + \(triggers)" }
|
|
|
|
|
|
}
|
|
|
|
func getTriggersForReminder(reminder: Reminder) -> [UNCalendarNotificationTrigger] {
|
|
return reminder.when.map {
|
|
let components = NSCalendar.current.dateComponents([.second, .minute, .hour], from: $0)
|
|
return UNCalendarNotificationTrigger(dateMatching: components, repeats: true)
|
|
}
|
|
}
|
|
|
|
func getIdentifier(reminder: Reminder, trigger: UNCalendarNotificationTrigger) -> String {
|
|
return "\(reminder.label)-\(trigger.dateComponents.hour ?? -1)-\(trigger.dateComponents.minute ?? -1)"
|
|
}
|