NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

SOLVED: EKEvent and ForEach

Forums > SwiftUI

So I have this Array of EKEvent,

var events: [EKEvent] { get }

Where I load the users calender event without any problem, the probem comes when I use my Foreach to try and acess the data:

ForEach(, id: \.eventIdentifier ) { event in
                HStack {
                    RoundedRectangle(cornerRadius: 25, style: .continuous)
                        .frame(width: 4, height: 20)
                    VStack {

Using this I can acess some of the parameters inside events, like title, calender ect. But I get error if I try to acess startDate or endDate, saying there is no such parameter inside EKCalenderItem. If i use print(event) I get:

EKEvent <0x600001508780>
     EKEvent <0x600001508780>
{    title =        Daddade; 
     location =     (null); 
     calendar =     EKCalendar <0x6000031fb840> {title = Calendar; type = Local; allowsModify = YES; color = #1BADF8;}; 
     alarms =       (null); 
     URL =          ; 
     lastModified = 2021-04-04 21:18:28 +0000; 
     startTimeZone =    Europe/Stockholm (GMT+2) offset 7200 (Daylight); 
     endTimeZone =  Europe/Stockholm (GMT+2) offset 7200 (Daylight) 
     location =     (null); 
     structuredLocation =   (null); 
     startDate =    2021-04-04 15:45:00 +0000; 
     endDate =      2021-04-04 16:45:00 +0000; 
     allDay =       0; 
     floating =     0; 
     recurrence =   (null); 
     travelTime =   (null); 
     startLocation =    (null);

I suspect it has something to do with my foreach and the id, anyone got any deas how do acess, startDate?



I remember having some issues with EKEvent in ForEach, when trying to conform it to Identifiable. However accessing start and end dates should work fine. I have this example project on GitHub where I do just that :-)


Huge thanks for that goldmine of information and inspiration!

Something is definitly wierd with EKEvent and for each, I made this:

var start: Date {

Inspired with how you handled calender color and suddenly it works.. so for sure something that is wrong there. Anyways, problem solved for me and I will reread some of your code to improve how I handle my own, huge thanks :)


I am super glad it helped! :-)


Hacking with Swift is sponsored by Instabug

SPONSORED Catch bugs as soon as they happen and know exactly why a crash occurred. Instabug's SDK grabs all the logs they need to fix bugs, crashes and performance issues in minutes instead of days. Get screenshots, device details, network logs, repro steps, and tons of other critical insights needed to resolve issues and prioritize product backlogs straight from your dashboard. It only takes a minute to integrate!

Get started now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.