Skip to content

Commit

Permalink
fix(iOS): properly handle date types during JSValue coercion (#4043)
Browse files Browse the repository at this point in the history
  • Loading branch information
theproducer committed Jan 13, 2021
1 parent 7bb9e0f commit 1affae7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ios/Capacitor/Capacitor/JSTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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? {
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1affae7

Please sign in to comment.