gpt4 book ai didi

swift - 从 Swift 中的日历中删除所有事件

转载 作者:搜寻专家 更新时间:2023-11-01 05:46:08 25 4
gpt4 key购买 nike

是否有一个命令可以从 Swift 中的日历中删除所有事件?

最佳答案

考虑到您将事件保存在 startDate,endDate,description 和一个 title

var event:EKEvent = EKEvent(eventStore: eventStore)
event.title = "Test Title"
event.startDate = NSDate()
event.endDate = NSDate()
event.notes = "This is a note"
event.calendar = eventStore.defaultCalendarForNewEvents
eventStore.saveEvent(event, span: EKSpanThisEvent, error: nil)

然后你需要做的就是像这样删除事件:

  var startDate=NSDate().dateByAddingTimeInterval(-60*60*24)
var endDate=NSDate().dateByAddingTimeInterval(60*60*24*3)
var predicate2 = eventStore.predicateForEventsWithStartDate(startDate, endDate: endDate, calendars: nil)

println("startDate:\(startDate) endDate:\(endDate)")
var eV = eventStore.eventsMatchingPredicate(predicate2) as [EKEvent]!

if eV != nil {
for i in eV {
println("Title \(i.title)" )
println("stareDate: \(i.startDate)" )
println("endDate: \(i.endDate)" )
do{
(try eventStore.removeEvent(i, span: EKSpan.ThisEvent, commit: true))
}
catch let error {
}

}
}
}

关于swift - 从 Swift 中的日历中删除所有事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29681319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com