I have a function that adds a new reminder. In this function, the reminder will have a reminder title and an alarm for a specific day and time.
The function currently looks like this:
var eventStore = EKEventStore()
var reminders = [EKReminder]()
func addReminder(date: Date, reminderTitle: String) {
eventStore.requestAccess(to: EKEntityType.reminder, completion: {
granted, error in
if (granted) && (error == nil) {
let reminder:EKReminder = EKReminder(eventStore: self.eventStore)
reminder.title = reminderTitle
let alarmTime = date
let alarm = EKAlarm(absoluteDate: alarmTime)
reminder.addAlarm(alarm)
reminder.calendar = self.eventStore.defaultCalendarForNewReminders()
do {
try self.eventStore.save(reminder, commit: true)
} catch {
print("Cannot save")
return
}
print("Reminder saved")
}
})
}
Now, I would like to add an EKRecurrenceRule that will repeat the alarm/reminder on a weekly basis forever (without a specific end date).
For a better explanation, this is the example of how I want my reminder to look in the end: Example
This is the approach I have already tried:
let recurrenceRule = EKRecurrenceRule(recurrenceWith: .weekly, interval: 1, daysOfTheWeek: [EKRecurrenceDayOfWeek(.monday)], daysOfTheMonth: nil, monthsOfTheYear: nil, weeksOfTheYear: nil, daysOfTheYear: nil, setPositions: nil, end: nil)
reminder.addRecurrenceRule(recurrenceRule)
Basically this should repeat the reminder every Monday, but for some reason, I cannot save the reminder.
Any help on how to successfully save a reminder?