[英]How to delete all events from the default calendar
How can I delete all events in the default calendar when a button is tapped? 轻按按钮时,如何删除默认日历中的所有事件?
This is my current code 这是我当前的代码
@IBAction func deleteEvents(_ sender: UIButton) {
eventStore.calendars(for: .event).removeAll()
}
The first problem it's not the current calendar. 第一个问题不是当前日历。 The second problem is that I get the following error:
第二个问题是出现以下错误:
Error: 错误:
Cannot use mutating member on immutable value: function call returns immutable value
无法对不可变值使用变异成员:函数调用返回不可变值
There is no removeAll
method. 没有
removeAll
方法。
You need to use the methods of EKEventStore
to query and remove the desired events. 您需要使用
EKEventStore
的方法来查询和删除所需的事件。
At a high level you need to: 在较高级别,您需要:
EKCalendar
. EKCalendar
的参考。 All of the needed APIs are in the EKEventStore
class. 所有必需的API都在
EKEventStore
类中。 See its documentation for specifics. 有关详细信息,请参见其文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.