如何获取 EKEvent 实例的 travelTime

How to get the travelTime of an EKEvent instance

我想获取日历事件 (EKEvent) 的旅行时间,但出现此错误:Value of type 'EKEvent' has no member 'travelTime'

当我打印 EKEvent 时,我得到这个:

EKEvent <0x79f6f460>
{
     EKEvent <0x79f6f460>
{    title =        Test; 
     location =     Foobar; 
     calendar =     EKCalendar <0x7ba6f9a0> {title = Calendar; type = Local; allowsModify = NO; color = #1BADF8;}; 
     alarms =       (null); 
     URL =          (null); 
     lastModified = 2016-04-25 17:56:58 +0000; 
     startTimeZone =    Europe/Amsterdam (GMT+2) offset 7200 (Daylight); 
     startTimeZone =    Europe/Amsterdam (GMT+2) offset 7200 (Daylight) 
}; 
     location =     Foobar; 
     structuredLocation =   EKStructuredLocation <0x79e722e0> {title = Foobar; address = (null); geo = (null); abID = (null); routing = (null); radius = 0.000000;}; 
     startDate =    2016-04-25 19:15:00 +0000; 
     endDate =      2016-04-25 20:15:00 +0000; 
     allDay =       0; 
     floating =     0; 
     recurrence =   (null); 
     attendees =    (null); 
     travelTime =   30 minutes; 
     startLocation =    (null);
};

有人知道发生了什么事吗? (我可以访问 startDate 的标题之类的东西)

这似乎return以秒为单位的旅行时间属性:

 let travelTime = yourEKEvent.valueForKey("travelTime")!

显然 EKEvent class 中没有可访问的 travelTime 属性 所以我猜它在它的超级 classes 中的某个地方。在内置的 iOS 日历中,当您向事件添加旅行时间时,选项的详细信息如下:

Event alerts will take this time into account and your calendar will be blocked during this time

查看EKAlarms 文档后,我认为它可能存储在relativeOffset 属性 中。警报应存储在 EKCalendar super class 中。

也可以通过设置值的方式更新数值:

yourEKEvent.setValue(300, forKey: "travelTime")

然后使用如下方法重新保存事件:

    func updateEvent(event: EKEvent)
{
    do {
        try eventStore.saveEvent(event, span: .ThisEvent)
        savedEventId = event.eventIdentifier

    } catch {
        print("Bad things happened")
    }
}