11import EventKit
22import Foundation
33
4- struct Event : Codable , KeyPathAccessible {
4+ struct Event : Codable , ReverseCodable {
55 // An EKEvent has three different identifiers
66 // 1. calendarItemIdentifier (via EKCalendarItem)
77 // 2. calendarItemExternalIdentifier (via EKCalendarItem)
@@ -36,7 +36,7 @@ struct Event: Codable, KeyPathAccessible {
3636 let services : [ Service : String ]
3737 let tags : [ String ]
3838
39- enum CodingKeys : String , CodingKey {
39+ enum CodingKeys : String , CodingKey , CaseIterable {
4040 case id
4141 case calendar
4242 case title
@@ -47,8 +47,17 @@ struct Event: Codable, KeyPathAccessible {
4747 case tags
4848 }
4949
50- static func codingKey( for key: String ) -> CodingKey ? {
51- return CodingKeys ( stringValue: key)
50+ static func reverseCodingKeys( ) -> [ String : String ] {
51+ return [
52+ CodingKeys . id. rawValue: " id " ,
53+ CodingKeys . calendar. rawValue: " calendar " ,
54+ CodingKeys . title. rawValue: " title " ,
55+ CodingKeys . schedule. rawValue: " schedule " ,
56+ CodingKeys . location. rawValue: " location " ,
57+ CodingKeys . meeting. rawValue: " meeting " ,
58+ CodingKeys . services. rawValue: " services " ,
59+ CodingKeys . tags. rawValue: " tags " ,
60+ ]
5261 }
5362}
5463
0 commit comments