Skip to content

Commit

Permalink
fix: add support for CGFloat property values (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancrosby-bl authored Oct 16, 2023
1 parent b05db31 commit 6de48f0
Show file tree
Hide file tree
Showing 2 changed files with 13 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 @@ -130,6 +130,8 @@ extension KeyedEncodingContainer {
try container.encodeIfPresent(val, forKey: JSONCodingKeys(stringValue: item.key)!)
} else if let val = item.value as? Float {
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? Bool {
try container.encodeIfPresent(val, forKey: JSONCodingKeys(stringValue: item.key)!)
} else if let val = item.value as? [Any] {
Expand Down
12 changes: 11 additions & 1 deletion Tests/AmplitudeTests/Events/BaseEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ final class BaseEventTests: XCTestCase {
"string": "stringValue",
"array": [1, 2, 3],
"int64": 1 as Int64,
"int32": 1 as Int32
"int32": 1 as Int32,
"cgfloat": 3.14 as CGFloat,
"double": 3.14 as Double
]
)

Expand All @@ -52,6 +54,14 @@ final class BaseEventTests: XCTestCase {
baseEventDict!["event_properties"]!["int64" as NSString] as! Int64,
1
)
XCTAssertEqual(
baseEventDict!["event_properties"]!["cgfloat" as NSString] as! CGFloat,
3.14
)
XCTAssertEqual(
baseEventDict!["event_properties"]!["double" as NSString] as! Double,
3.14
)
XCTAssertEqual(
baseEventDict!["event_properties"]!["string" as NSString] as! String,
"stringValue"
Expand Down

0 comments on commit 6de48f0

Please sign in to comment.