richardtop / CalendarKit

📅 Calendar for Apple platforms in Swift
https://www.youtube.com/watch?v=cJ63-_z1qg8
MIT License
2.48k stars 333 forks source link

Event has no starDate or endDate #343

Closed R35Master closed 1 year ago

R35Master commented 1 year ago

New Issue Checklist

Issue Description

Hi,

I was following the latest guide on youtube to implement CK to my app. At the very beginning I had the issue "Value of type 'Event' has no member 'startDate'"

and I checked the document(EVENT.SWIFT) with option key > go to document and literally I couldnt find startDate or endDate.

Screen Shot 2022-08-15 at 21 18 18

Any ideas?

Code I'm using with CalendarKit

    override func eventsForDate(_ date: Date) -> [EventDescriptor] {

        let startDate = date

        var oneDayComponents = DateComponents()
        oneDayComponents.day = 1

        let endDate = calendar.date(byAdding: oneDayComponents, to: startDate)!

        let predicate = eventStore.predicateForEvents(withStart: startDate, end: endDate, calendars: nil)

        let eventKitEvents = eventStore.events(matching: predicate)

        let calenderKitEvents = eventKitEvents.map { ekEvent -> Event in
            let ckEvent = Event()
       //    ckEvent.startDate = ekEvent.startDate <<<<
       //    ckEvent.endDate = ekEvent.endDate <<<<
            ckEvent.isAllDay = ekEvent.isAllDay
            ckEvent.text = ekEvent.title
            if let eventColor = ekEvent.calendar.cgColor {
                ckEvent.color = UIColor(cgColor: eventColor)
            }
            return ckEvent
        }
        return calenderKitEvents
    }
}

Result I am trying to achieve

R35Master commented 1 year ago

@richardtop Hi mate, could you please guide me what to do hear?

richardtop commented 1 year ago

Hi, the API has changed here: https://github.com/richardtop/CalendarKit/releases/tag/1.1.0

Now the API requires to set DateInterval: https://developer.apple.com/documentation/foundation/dateinterval

Video & discussion of the change with example: https://www.youtube.com/watch?v=rmO0TT3mQIM

Video tutorial of how to change the app (section "Refactoring the demo app"): https://youtu.be/rmO0TT3mQIM?t=1360

The latest version of the EKWrapper.swift with the relevant line highlighted: https://github.com/richardtop/CalendarApp/blob/master/Calendar/EKWrapper.swift#L13

R35Master commented 1 year ago

Much appreciated @richardtop

richardtop commented 1 year ago

In case you don't have further questions, feel free to close this issue.