0

Because EKEvent can not hold extra properties, I was thinking of creating my own class Event and inherit from EKCalendarItem (same as EKEvent class).

But I get a FrozenClass error, which is quite new to me. Does anybody have any idea of what that means? EKCalendarItem is an open class, so as far as I know I should be able to inherit from that. Or... am I wrong here?

The exact error:

'+[MyApp.Event frozenClass]: unrecognized selector sent to class 0x105667068'

My code:

class Event: EKCalendarItem {

// MARK: - Properties

var id: String
var startDate: Date
var endDate: Date
var isAllDay: Bool

// MARK: - Inits

init?(id: String, dictionary: [String: Any]) {
    guard
        let title = dictionary["title"] as? String,
        let startDate = dictionary["startDate"] as? Timestamp,
        let endDate = dictionary["endDate"] as? Timestamp,
        let isAllDay = dictionary["isAllDay"] as? Bool
        else { return nil }

    self.id = id
    self.startDate = startDate.dateValue()
    self.endDate = endDate.dateValue()
    self.isAllDay = isAllDay

    super.init()

    self.location = dictionary["location"] as? String
    self.title = title
    self.notes = dictionary["notes"] as? String
}

convenience init?(snapshot: QueryDocumentSnapshot) {
    self.init(id: snapshot.documentID, dictionary: snapshot.data())
}

}

Silviu B.
  • 43
  • 8
  • Why not use `EKEvent` instead of your own `Event` class? It has `startDate`, `endDate`, and `isAllDay` and you get a `uuid` from `EKCalendarItem`. – rmaddy Mar 11 '19 at 22:38
  • Because I'm building a shared calendar which is saved to Firebase. That means the unique id for the event needs to be the one from the Firebase database, not the one local. And the eventId property on the EKEvent is a get only. I will also need to add some more properties too. – Silviu B. Mar 12 '19 at 08:57
  • Basically, the event can be amended by any of the attendants on their own devices and that gets saved to Firebase. I can't keep track of the eventId property any other way, unless it's saved into one (common) database. – Silviu B. Mar 12 '19 at 09:00
  • @SilviuB. did you find a fix? – vahidgr Jul 11 '21 at 06:31

0 Answers0