Skip to content

Commit

Permalink
fix: add support for Decimal property values (#187)
Browse files Browse the repository at this point in the history
* fix: add support for Decimal property values

* fixed lint warnings
  • Loading branch information
doctorcooper authored Jul 8, 2024
1 parent 48b9a37 commit c838bd9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Sources/Amplitude/Utilities/CodableExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ extension KeyedEncodingContainer {
try container.encodeIfPresent(val, forKey: JSONCodingKeys(stringValue: item.key)!)
} else if let val = item.value as? CGFloat {
try container.encodeIfPresent(val, forKey: JSONCodingKeys(stringValue: item.key)!)
} else if let val = item.value as? Decimal {
try container.encodeIfPresent(val, forKey: JSONCodingKeys(stringValue: item.key)!)
} else if let val = item.value as? Bool {
try container.encodeIfPresent(val, forKey: JSONCodingKeys(stringValue: item.key)!)
} else if let val = item.value as? [Any] {
Expand Down
7 changes: 6 additions & 1 deletion Tests/AmplitudeTests/Events/BaseEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ final class BaseEventTests: XCTestCase {
"int64": 1 as Int64,
"int32": 1 as Int32,
"cgfloat": 3.14 as CGFloat,
"double": 3.14 as Double
"double": 3.14 as Double,
"decimal": 3.14 as Decimal
]
)

Expand Down Expand Up @@ -62,6 +63,10 @@ final class BaseEventTests: XCTestCase {
baseEventDict!["event_properties"]!["double" as NSString] as! Double,
3.14
)
XCTAssertEqual(
Decimal(baseEventDict!["event_properties"]!["decimal" as NSString] as! Double),
Decimal(3.14)
)
XCTAssertEqual(
baseEventDict!["event_properties"]!["string" as NSString] as! String,
"stringValue"
Expand Down

0 comments on commit c838bd9

Please sign in to comment.