gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 14:24:52 29 4
gpt4 key购买 nike

在 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? 返回一个 EKCalendarItem。

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

最佳答案

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

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

关于ios - 如何在 EventKit 中使用 CalendarIdentifier 获取提醒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51691988/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com