gpt4 book ai didi

ios - 获取 EKEvent 的日历标题

转载 作者:可可西里 更新时间:2023-11-01 02:05:08 25 4
gpt4 key购买 nike

我有一组从不同日历中获取的 EKEvents。现在我想在 tableView 中显示事件 + 相应日历的名称。

cell.textLabel?.text = event.calendar.title

但这总是返回一个空字符串(甚至不是 nil 而只是 "")。有没有办法访问随机EKEvent对象对应日历的信息?

最佳答案

这将获取明年(大约)的所有事件,然后打印出事件标题和它所属的日历的标题:

    var allEvents: [EKEvent] = []

let eventStore = EKEventStore()
let calendars = eventStore.calendars(for: .event)

for calendar in calendars {

// end date (about) one year from now
let endDate = Date(timeIntervalSinceNow: 60*60*24*365)

let predicate = eventStore.predicateForEvents(withStart: Date(), end: endDate as Date, calendars: [calendar])

let events = eventStore.events(matching: predicate)

allEvents.append(contentsOf: events)

}

for event in allEvents {
print(event.title, "in", event.calendar.title)
}

关于ios - 获取 EKEvent 的日历标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43502558/

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