diff --git a/Sources/Amplitude/Utilities/CodableExtension.swift b/Sources/Amplitude/Utilities/CodableExtension.swift index 93f1f325..13912a16 100644 --- a/Sources/Amplitude/Utilities/CodableExtension.swift +++ b/Sources/Amplitude/Utilities/CodableExtension.swift @@ -118,16 +118,8 @@ extension KeyedEncodingContainer { } var container = self.nestedContainer(keyedBy: JSONCodingKeys.self, forKey: key) for item in safeValue { - if let val = item.value as? Int { - try container.encodeIfPresent(val, forKey: JSONCodingKeys(stringValue: item.key)!) - } else if let val = item.value as? String { - try container.encodeIfPresent(val, forKey: JSONCodingKeys(stringValue: item.key)!) - } else if let val = item.value as? Double { - 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? Bool { - try container.encodeIfPresent(val, forKey: JSONCodingKeys(stringValue: item.key)!) + if let val = item.value as? Encodable { + try container.encode(val, forKey: JSONCodingKeys(stringValue: item.key)!) } else if let val = item.value as? [Any] { try container.encodeIfPresent(val, forKey: JSONCodingKeys(stringValue: item.key)!) } else if let val = item.value as? [String: Any] { diff --git a/Tests/AmplitudeTests/Events/BaseEventTests.swift b/Tests/AmplitudeTests/Events/BaseEventTests.swift index c488d9f1..240903ca 100644 --- a/Tests/AmplitudeTests/Events/BaseEventTests.swift +++ b/Tests/AmplitudeTests/Events/BaseEventTests.swift @@ -28,6 +28,8 @@ final class BaseEventTests: XCTestCase { "integer": 1, "string": "stringValue", "array": [1, 2, 3], + "int64": 1 as Int64, + "int32": 1 as Int32 ] ) @@ -42,6 +44,14 @@ final class BaseEventTests: XCTestCase { baseEventDict!["event_properties"]!["integer" as NSString] as! Int, 1 ) + XCTAssertEqual( + baseEventDict!["event_properties"]!["int32" as NSString] as! Int32, + 1 + ) + XCTAssertEqual( + baseEventDict!["event_properties"]!["int64" as NSString] as! Int64, + 1 + ) XCTAssertEqual( baseEventDict!["event_properties"]!["string" as NSString] as! String, "stringValue"