From 6de48f014c7ac80b83ad94e0cfa748ddc0d7908e Mon Sep 17 00:00:00 2001 From: Ryan Crosby <97980537+ryancrosby-bl@users.noreply.github.com> Date: Mon, 16 Oct 2023 16:12:07 -0700 Subject: [PATCH] fix: add support for CGFloat property values (#91) --- Sources/Amplitude/Utilities/CodableExtension.swift | 2 ++ Tests/AmplitudeTests/Events/BaseEventTests.swift | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/Amplitude/Utilities/CodableExtension.swift b/Sources/Amplitude/Utilities/CodableExtension.swift index 181a007a..a9a19f8b 100644 --- a/Sources/Amplitude/Utilities/CodableExtension.swift +++ b/Sources/Amplitude/Utilities/CodableExtension.swift @@ -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] { diff --git a/Tests/AmplitudeTests/Events/BaseEventTests.swift b/Tests/AmplitudeTests/Events/BaseEventTests.swift index 240903ca..5f03ffb3 100644 --- a/Tests/AmplitudeTests/Events/BaseEventTests.swift +++ b/Tests/AmplitudeTests/Events/BaseEventTests.swift @@ -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 ] ) @@ -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"