如何在 EventKit 中使用 CalendarIdentifier 获取提醒?

How to fetch Reminder with CalendarIdentifier in EventKit?

在 Apple 文档中 使用唯一标识符搜索

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.

我的问题是我想获取一个 EKReminder 以使用 isCompleted 属性。

 // 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)
}

但是
方法 func calendarItem(withIdentifier identifier: String) -> EKCalendarItem? return 一个 EKCalendarItem。

我不想使用 for 循环来准确搜索我想要的提醒。 有什么办法吗?

EKCalendarItemEKReminderEKEvent 的基础 class。如果您知道日历项是提醒,则将其转换为 EKReminder

let reminder = store.calendarItem(withIdentifier: identifier) as! EKReminder