在 Apple 的 EventKit 中,每个日历都可以有一个用户可定义的颜色,也可以在 EKCalendar 实例上以EKCalendar.color
. 如何从单个事件(而不是日历)访问该颜色?是否有从 EKEvent 实例到事件所属的 EKCalendar 的任何反向引用?
例如,我有一个日历列表,并按开始和结束日期获取事件。在由此产生的事件数组中,似乎任何回答“单个事件来自哪个日历”的问题的信息都丢失了。
import EventKit
let eventStore = EKEventStore()
let calendars: [EKCalendar] = getCalendars() // get some calendars here
let d = (start: Date(), end: Date().addingTimeInterval(3600*5)) // [now, now+5h]
let predicate = eventStore.predicateForEvents(withStart: d.start, end: d.end, calendars: calendars)
let events = eventStore.events(matching: predicate) // fetch the events
for event in events { // iterate over all events from calendars within [now, now+5h]
// ?? how to get the color of the calendar of event? or
// ?? how to get the EKCalendar instance event is from?
}