嘿,伙计们,我是斯威夫特和事件工具包的新手,我有这行代码,我可以从中打印事件而不是日历名称吗?
var eventStore = EKEventStore()
eventStore.requestAccessToEntityType(EKEntityTypeEvent,
completion: {(granted: Bool, error:NSError!) in
if !granted {
println("Access to store not granted")
}
})
let events = eventStore.calendarsForEntityType(EKEntityTypeEvent)
for events in events as [EKCalendar] {
println("events = \(events.title)")
}
最佳答案
我知道有两种方法可以从EKEventStore获取事件,但是它们都需要一个谓词,通常使用开始/结束日期和一个日历数组来检查。
let predicate = store.predicateForEventsWithStartDate(startDate, endDate: endDate, calendars: nil) // nil calendar checks all calendars, otherwise pass [EKCalendar]
使用:
let events = store.eventsMatchingPredicate(predicate) as [EKEvent]
或:
store.enumerateEventsMatchingPredicate(predicate) { event, stop in
}
关于ios - SWIFT和EventKit,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29186703/