From 71911a83c9adc6f45523217bacff7b4ff3f83df9 Mon Sep 17 00:00:00 2001 From: Jason Bruder Date: Mon, 20 Feb 2023 13:00:13 -0500 Subject: [PATCH 1/4] Update ThingsJSON.swift Resolves "Enum case 'invalidType' has 2 associated values; matching them as a tuple is deprecated" warning. --- ThingsJSON.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ThingsJSON.swift b/ThingsJSON.swift index 8d79b0e..2bb01c2 100644 --- a/ThingsJSON.swift +++ b/ThingsJSON.swift @@ -66,7 +66,7 @@ public class TJSContainer : Codable { let todo = try container.decode(TJSTodo.self) self = .todo(todo) } - catch TJSError.invalidType(_) { + catch TJSError.invalidType(_, _) { // If it's the wrong type, try a project let project = try container.decode(TJSProject.self) self = .project(project) @@ -486,7 +486,7 @@ public class TJSProject : TJSModelItem, Codable { let todo = try container.decode(TJSTodo.self) self = .todo(todo) } - catch TJSError.invalidType(_) { + catch TJSError.invalidType(_, _) { // If it's the wrong type, try a heading let heading = try container.decode(TJSHeading.self) self = .heading(heading) From c3e85c913f6073f500f943156457d266f1967b26 Mon Sep 17 00:00:00 2001 From: Jace Kalms Date: Mon, 27 Feb 2023 11:46:15 +0100 Subject: [PATCH 2/4] Tweak unused parameters --- ThingsJSON.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ThingsJSON.swift b/ThingsJSON.swift index 2bb01c2..1eedc84 100644 --- a/ThingsJSON.swift +++ b/ThingsJSON.swift @@ -66,7 +66,7 @@ public class TJSContainer : Codable { let todo = try container.decode(TJSTodo.self) self = .todo(todo) } - catch TJSError.invalidType(_, _) { + catch TJSError.invalidType(expectedType: _, errorContext: _) { // If it's the wrong type, try a project let project = try container.decode(TJSProject.self) self = .project(project) @@ -486,7 +486,7 @@ public class TJSProject : TJSModelItem, Codable { let todo = try container.decode(TJSTodo.self) self = .todo(todo) } - catch TJSError.invalidType(_, _) { + catch TJSError.invalidType(expectedType: _, errorContext: _) { // If it's the wrong type, try a heading let heading = try container.decode(TJSHeading.self) self = .heading(heading) From 61649b06dbd7eaac0f401ba5b2e466cbe8bbff8e Mon Sep 17 00:00:00 2001 From: Jace Kalms Date: Mon, 27 Feb 2023 11:46:35 +0100 Subject: [PATCH 3/4] Remove unnecessary #available checks for very old OS's --- ThingsJSON.swift | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/ThingsJSON.swift b/ThingsJSON.swift index 1eedc84..2612a6b 100644 --- a/ThingsJSON.swift +++ b/ThingsJSON.swift @@ -648,31 +648,12 @@ private enum TJSError : Error { /// /// Use to with a JSONEncoder to correctly format dates. public func ThingsJSONDateEncodingStrategy() -> JSONEncoder.DateEncodingStrategy { - if #available(iOS 10, OSX 10.12, *) { - return .iso8601 - } - else { - return .formatted(isoDateFormatter()) - } + return .iso8601 } /// A date decoding strategy to format a date according to ISO8601. /// /// Use to with a JSONDecoder to correctly format dates. public func ThingsJSONDateDecodingStrategy() -> JSONDecoder.DateDecodingStrategy { - if #available(iOS 10, OSX 10.12, *) { - return .iso8601 - } - else { - return .formatted(isoDateFormatter()) - } -} - -private func isoDateFormatter() -> DateFormatter { - let dateFormatter = DateFormatter() - dateFormatter.locale = Locale(identifier: "en_US_POSIX") - dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" - dateFormatter.timeZone = TimeZone(secondsFromGMT: 0) - - return dateFormatter + return .iso8601 } From 0862eaaba247974f998749a893b3d6c94784e84c Mon Sep 17 00:00:00 2001 From: Jace Kalms Date: Mon, 27 Feb 2023 11:46:56 +0100 Subject: [PATCH 4/4] Add the heading-id parameter to TJSTodo --- ThingsJSON.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ThingsJSON.swift b/ThingsJSON.swift index 2612a6b..7677215 100644 --- a/ThingsJSON.swift +++ b/ThingsJSON.swift @@ -163,6 +163,7 @@ public class TJSTodo : TJSModelItem, Codable { public var appendChecklistItems: [TJSChecklistItem]? public var listID: String? public var list: String? + public var headingID: String? public var heading: String? public var completed: Bool? public var canceled: Bool? @@ -184,6 +185,7 @@ public class TJSTodo : TJSModelItem, Codable { case appendChecklistItems = "append-checklist-items" case listID = "list-id" case list + case headingID = "heading-id" case heading case completed case canceled @@ -208,6 +210,7 @@ public class TJSTodo : TJSModelItem, Codable { appendChecklistItems: [TJSChecklistItem]? = nil, listID: String? = nil, list: String? = nil, + headingID: String? = nil, heading: String? = nil, completed: Bool? = nil, canceled: Bool? = nil, @@ -232,6 +235,7 @@ public class TJSTodo : TJSModelItem, Codable { self.listID = listID self.list = list self.heading = heading + self.headingID = headingID self.completed = completed self.canceled = canceled self.creationDate = creationDate @@ -255,6 +259,7 @@ public class TJSTodo : TJSModelItem, Codable { appendChecklistItems: todo.appendChecklistItems, listID: todo.listID, list: todo.list, + headingID: todo.headingID, heading: todo.heading, completed: todo.completed, canceled: todo.canceled, @@ -281,6 +286,7 @@ public class TJSTodo : TJSModelItem, Codable { appendChecklistItems = try attributes.decodeIfPresent([TJSChecklistItem].self, forKey: .appendChecklistItems) listID = try attributes.decodeIfPresent(String.self, forKey: .listID) list = try attributes.decodeIfPresent(String.self, forKey: .list) + headingID = try attributes.decodeIfPresent(String.self, forKey: .headingID) heading = try attributes.decodeIfPresent(String.self, forKey: .heading) completed = try attributes.decodeIfPresent(Bool.self, forKey: .completed) canceled = try attributes.decodeIfPresent(Bool.self, forKey: .canceled) @@ -309,6 +315,7 @@ public class TJSTodo : TJSModelItem, Codable { try attributes.encodeIfPresent(appendChecklistItems, forKey: .appendChecklistItems) try attributes.encodeIfPresent(listID, forKey: .listID) try attributes.encodeIfPresent(list, forKey: .list) + try attributes.encodeIfPresent(headingID, forKey: .headingID) try attributes.encodeIfPresent(heading, forKey: .heading) try attributes.encodeIfPresent(completed, forKey: .completed) try attributes.encodeIfPresent(canceled, forKey: .canceled)