我想获得日历活动(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的标题就好了)
答案 0 :(得分:2)
这似乎以秒为单位返回旅行时间属性:
let travelTime = yourEKEvent.valueForKey("travelTime")!
显然travelTime
类中没有可访问的EKEvent
属性,所以我猜它在超类中的某处。在内置iOS日历中,当您向活动添加旅行时间时,选项的详细信息为:
事件提醒会将此时间考虑在内,您的日历将在此期间被阻止
查看EKAlarms
文档后,我认为它可能存储在relativeOffset
属性中。警报应存储在EKCalendar
超类中。
您还可以按设置值方法更新值:
yourEKEvent.setValue(300, forKey: "travelTime")
然后使用如下方法重新保存事件:
func updateEvent(event: EKEvent)
{
do {
try eventStore.saveEvent(event, span: .ThisEvent)
savedEventId = event.eventIdentifier
} catch {
print("Bad things happened")
}
}