因为 EKEvent 不能保存额外的属性,所以我正在考虑创建自己的 Event 类并从 EKCalendarItem 继承(与 EKEvent 类相同)。
但是我收到了一个 FrozenClass 错误,这对我来说很新鲜。有人知道这意味着什么吗?EKCalendarItem 是一个开放类,据我所知,我应该能够从中继承。或者……我错了吗?
确切的错误:
'+[MyApp.Event frozenClass]: 无法识别的选择器发送到类 0x105667068'
我的代码:
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())
}
}