I tried to fetching calendar, I have no problem with title, color, start/end date, etc...but I decision to add "Invited" but I keep getting error said:
For-in loop requires '[EKParticipant]?' to conform to 'Sequence'; did you mean to unwrap optional?
Here my codes:
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)")
}
}
I want to get name/email (for now) from attendees into the string. How can I do that?
Thank you
unwrap the optional get_event.attendees before looping through it
if let attendees = get_event.attendees {
for attendee in attendees {
// do your code here
print(attendee.name ?? "")
}
}
https://developer.apple.com/documentation/eventkit/ekparticipant