in Apple Documentation Search with Unique Identifiers
If you know the event’s unique identifier because you fetched it previously with a predicate, you can use the EKEventStore method event(withIdentifier:) to fetch the event. If it is a recurring event, this method will return the first occurrence of the event. You can get an event’s unique identifier with the eventIdentifier property.
Similarly, if you know a specific reminder’s unique identifier from previously fetching it with a predicate, you can call the calendarItem(withIdentifier:) instance method. calendarItem(withIdentifier:) can fetch any calendar item (reminders and events), whereas event(withIdentifier:) fetches only events.
My problem is I want fetch A EKReminder to use isCompleted
property.
// Mark reminder as completed
// Use the completed property to mark a reminder as completed
func complete(_ reminder: EKReminder) {
reminder.isCompleted = true
/* Some my customize code */
// Update the reminder
self.save(reminder)
}
but
method func calendarItem(withIdentifier identifier: String) -> EKCalendarItem?
return an EKCalendarItem.
I dont want use for loop to search exactly Reminder I wanted. Is there any way?
EKCalendarItem
is the base class of EKReminder
and EKEvent
. If you know that the calendar item is a reminder cast it to EKReminder
let reminder = store.calendarItem(withIdentifier: identifier) as! EKReminder