Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Boris Kamp
Boris Kamp
16,660 Points

Failed to get melted object for frozen object related by key calendar

Hi guys!

I'm implementing a calendar in my app but am having an error I can't seem to figure out.

I fetch all my events with the following code:

class func loadAllEvents(forDate startDate: Date) -> [EKEvent] {

    let calendar = Calendar.current
    let endDate = calendar.date(byAdding: .day, value: 1, to: startDate)

    let eventStore = EKEventStore()
    // Use an event store instance to create and properly configure an NSPredicate
    let eventsPredicate = eventStore.predicateForEvents(withStart: startDate, end: endDate!, calendars: nil)

    // Use the configured NSPredicate to find and return events in the store that match
    let events: [EKEvent] = eventStore.events(matching: eventsPredicate)

    return events
}

then in my tableview I have the following function to load the events in viewdidload:

var dates: [Date] = []
var events: [[EKEvent]] = []

func loadCalendarData() {
    let newDates = Services.returnDatesBetweenInterval(Services.dateFromString("2018-01-22"), Services.dateFromString("2018-02-28"))

    var newEvents: [[EKEvent]] = []
    for date in newDates {
        newEvents.append(Services.loadAllEvents(forDate: date))
    }
    self.dates = newDates
    self.events = newEvents
}

whenever I do a dump(self.events) here, all events have their calendar assigned (event.calendar)

to show them in my tableview's cell I have the following dequeue function:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "calendarEntryCell", for: indexPath) as! CalendarItemTableViewCell

    //check if day has an event, if not display a default label
    if events[indexPath.section].indices.contains(indexPath.row) {
        let event: EKEvent = events[indexPath.section][indexPath.row]
        cell.event = event
        cell.placeHolderCell = false
    } else {
        cell.placeHolderCell = true
    }

    return cell
}

I have the following issue, the first two events have their calendar property set, the rest does not and has a null value!

this is my dumped first event:

- EKEvent <0x1c0117b20>
{
     EKEvent <0x1c0117b20>
{    title =        Grijze container; 
     location =     ; 
     calendar =     EKCalendar <0x1d4c6e380> {title = Prive; type = CalDAV; allowsModify = YES; color = #A32929FF;}; 
     alarms =       (
    "EKAlarm <0x1d02865e0> {triggerInterval = -300.000000}",
    "EKAlarm <0x1d0489600> {triggerInterval = -1800.000000}"
); 
     URL =          (null); 
     lastModified = 2018-01-22 07:27:36 +0000; 
     startTimeZone =    Europe/Amsterdam (CET) offset 3600; 
     startTimeZone =    Europe/Amsterdam (CET) offset 3600 
}; 
     location =     ; 
     structuredLocation =   EKStructuredLocation <0x1d4c68f00> {title = ; address = (null); geo = (null); abID = (null); routing = (null); radius = 0.000000;}; 
     startDate =    2018-01-22 06:30:00 +0000; 
     endDate =      2018-01-22 07:30:00 +0000; 
     allDay =       0; 
     floating =     0; 
     recurrence =   EKRecurrenceRule <0x1d4c68b80> RRULE FREQ=WEEKLY;INTERVAL=2;BYDAY=MO;WKST=SU; 
     attendees =    (
    "EKAttendee <0x1d0c69340> {UUID = 0DAB3E64-1BF6-4BAC-BB39-202996E70588; name = Boris Kamp; email = boriskamp1990@gmail.com; phone = (null); status = 2; role = 1; type = 1}",
    "EKAttendee <0x1d0c69f80> {UUID = 4E734F48-F9F6-4477-BF48-DC5B0FFD4F53; name = (null); email = thari.van.aalst@wereldhave.com; phone = (null); status = 1; role = 1; type = 1}"
); 
     travelTime =   (null); 
     startLocation =    (null);
};

and this is my dumped third event:

EKEvent <0x1c4117c40>
{
     EKEvent <0x1c4117c40>
{    title =        Sportavond; 
     location =     ; 
     calendar =     (null); 
     alarms =       (null); 
     URL =          (null); 
     lastModified = (null); 
     startTimeZone =    Europe/Amsterdam (CET) offset 3600; 
     startTimeZone =    Europe/Amsterdam (CET) offset 3600 
}; 
     location =     ; 
     structuredLocation =   (null); 
     startDate =    2018-01-22 18:30:00 +0000; 
     endDate =      2018-01-22 19:30:00 +0000; 
     allDay =       0; 
     floating =     0; 
     recurrence =   (null); 
     attendees =    (null); 
     travelTime =   (null); 
     startLocation =    (null);
}

aside from the dumped events console prints the following as well:

2018-01-22 13:58:19.769368+0100 DoToo[6285:3411976] [EventKit] Failed to get melted object for frozen object related by key structuredLocationWithoutPrediction. Event store is nil
2018-01-22 13:58:19.769378+0100 DoToo[6285:3411976] [EventKit] Failed to get melted object for frozen object related by key calendar. Event store is nil

How can this happen? I have really no clue and am banging my head on this one for a few hours now.

Thanks in advance!