我试图获取日历,标题,颜色,开始/结束日期等都没有问题,但是我决定添加“已邀请”,但我总是收到错误提示:
For-in loop requires '[EKParticipant]?' to conform to 'Sequence'; did you mean to unwrap optional?
这里是我的代码:
func create_currentevent_date() {
let endtime = Calendar.current.date(bySettingHour: 23, minute: 59, second: 59, of: Date())!
for get_category in date_calendar_category_user {
for search_category in eventStore.calendars(for: EKEntityType.event) {
if search_category.title == get_category {
for get_event in eventStore.events(matching: eventStore.predicateForEvents(withStart: Date(), end: endtime, calendars: [search_category])) {
let event_start = get_event.startDate.timeIntervalSince1970
let event_end = get_event.endDate.timeIntervalSince1970
let time_rightnow = Date().timeIntervalSince1970
for get_invite_detail in get_event.attendees { //THIS IS WHERE I GET ERROR MESSAGE
}
if time_rightnow >= event_start && time_rightnow <= event_end {
date_calendar_currentevent.append(calendar_getdetail(ce_title: get_event.title,
ce_category: get_event.calendar.title,
ce_color: get_event.calendar.cgColor,
ce_invited_name: "",
ce_invited_email: "",
ce_start: get_event.startDate,
ce_end: get_event.endDate))
}
}
}
}
}
for get_detal in date_calendar_currentevent {
print("\(get_detal.ce_invited_name) and \(get_detal.ce_invited_email)")
}
}
我想将与会者的姓名/电子邮件(现在)添加到字符串中。我该怎么办?
谢谢
循环遍历可选的get_event.attendees
if let attendees = get_event.attendees {
for attendee in attendees {
// do your code here
print(attendee.name ?? "")
}
}
https://developer.apple.com/documentation/eventkit/ekparticipant