From 1affae7cf8d2f49681bf25be48633ab985bbd12f Mon Sep 17 00:00:00 2001 From: Joey Pender Date: Tue, 12 Jan 2021 18:07:14 -0600 Subject: [PATCH] fix(iOS): properly handle date types during JSValue coercion (#4043) --- ios/Capacitor/Capacitor/JSTypes.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ios/Capacitor/Capacitor/JSTypes.swift b/ios/Capacitor/Capacitor/JSTypes.swift index 75b9dc1fe..f362b096a 100644 --- a/ios/Capacitor/Capacitor/JSTypes.swift +++ b/ios/Capacitor/Capacitor/JSTypes.swift @@ -9,6 +9,7 @@ extension Float: JSValue {} extension Double: JSValue {} extension NSNumber: JSValue {} extension Array: JSValue {} +extension Date: JSValue {} extension Dictionary: JSValue where Key == String, Value == JSValue {} // convenience aliases @@ -151,7 +152,7 @@ extension JSValueContainer { if let isoString = jsObjectRepresentation[key] as? String { return Self.jsDateFormatter.date(from: isoString) } - return nil + return jsObjectRepresentation[key] as? Date } public func getArray(_ key: String) -> JSArray? { @@ -201,6 +202,8 @@ private func coerceToJSValue(_ value: Any?) -> JSValue? { return floatValue case let doubleValue as Double: return doubleValue + case let dateValue as Date: + return dateValue case let arrayValue as NSArray: return arrayValue.compactMap { coerceToJSValue($0) } case let dictionaryValue as NSDictionary: