@@ -7,6 +7,7 @@ extension EKReminder: Encodable {
77 case notes
88 case url
99 case location
10+ case locationTitle
1011 case completionDate
1112 case isCompleted
1213 case priority
@@ -23,24 +24,37 @@ extension EKReminder: Encodable {
2324 try container. encode ( self . priority, forKey: . priority)
2425 try container. encode ( self . calendar. title, forKey: . list)
2526 try container. encodeIfPresent ( self . notes, forKey: . notes)
27+
28+ // url field is nil
29+ // https://developer.apple.com/forums/thread/128140
2630 try container. encodeIfPresent ( self . url, forKey: . url)
27- try container. encodeIfPresent ( self . location, forKey: . location)
28- try container. encodeIfPresent ( self . completionDate, forKey: . completionDate)
31+ try container. encodeIfPresent ( format ( self . completionDate) , forKey: . completionDate)
2932
30- if let startDateComponents = self . startDateComponents {
31- if #available( macOS 12 . 0 , * ) {
32- try container. encode ( startDateComponents. date? . ISO8601Format ( ) , forKey: . startDate)
33- } else {
34- try container. encode ( startDateComponents. date? . description ( with: . current) , forKey: . startDate)
33+ for alarm in self . alarms ?? [ ] {
34+ if let location = alarm. structuredLocation {
35+ try container. encodeIfPresent ( location. title, forKey: . locationTitle)
36+ if let geoLocation = location. geoLocation {
37+ let geo = " \( geoLocation. coordinate. latitude) , \( geoLocation. coordinate. longitude) "
38+ try container. encode ( geo, forKey: . location)
39+ }
40+ break
3541 }
3642 }
3743
44+ if let startDateComponents = self . startDateComponents {
45+ try container. encodeIfPresent ( format ( startDateComponents. date) , forKey: . startDate)
46+ }
47+
3848 if let dueDateComponents = self . dueDateComponents {
39- if #available( macOS 12 . 0 , * ) {
40- try container. encode ( dueDateComponents. date? . ISO8601Format ( ) , forKey: . dueDate)
41- } else {
42- try container. encode ( dueDateComponents. date? . description ( with: . current) , forKey: . dueDate)
43- }
49+ try container. encodeIfPresent ( format ( dueDateComponents. date) , forKey: . dueDate)
50+ }
51+ }
52+
53+ private func format( _ date: Date ? ) -> String ? {
54+ if #available( macOS 12 . 0 , * ) {
55+ return date? . ISO8601Format ( )
56+ } else {
57+ return date? . description ( with: . current)
4458 }
4559 }
4660}
0 commit comments