从Swift中的EKEvent获取日历颜色

伦尼

在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?
}
李维

它看起来像EKEvent是的子类EKCalendarItemEKCalendarItem包含的属性,calendar

话虽如此,这是问题的答案

...
for event in events { // iterate over all events from calendars within [now, now+5h]
   // ?? how to get the color of the calendar of 
   let color = event.calendar.color

   // ?? how to get the EKCalendar instance event is from?
   let calendar = event.calendar
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章