posthog-ios icon indicating copy to clipboard operation
posthog-ios copied to clipboard

Codable support

Open JoeFerrucci opened this issue 2 years ago • 3 comments

Is your feature request related to a problem?

You don't support Codable when using capture for events.

Describe the solution you'd like

Getting error: key does not conform to NSCoding and cannot be serialized for delivery.

Describe alternatives you've considered

Allow Codable

Additional context

Thanks! Looking forward to reply.

Thank you for your feature request – we love each and every one!

JoeFerrucci avatar May 19 '23 20:05 JoeFerrucci

@JoeFerrucci do you mean https://developer.apple.com/documentation/swift/codable ?

marandaneto avatar Oct 09 '23 10:10 marandaneto

Yes, that is the one. When I try to pass a dictionary into capture(event:properties:) it fails with that error.

Here is a trivial example to help highlight it

struct MyType: Codable {}

posthog?.capture("My Event", properties: ["somekey": MyType()])

This yields the error. Technically PostHog SDK only needs to support Encodable; it doesn't need to be Decodable

Note: the error appears at runtime when you try to send the data over the wire; it's not a compile time error.

JoeFerrucci avatar Oct 09 '23 14:10 JoeFerrucci

We're currently rewriting the iOS SDK and we'll consider this use case, thanks for the context. Edit: Consider using the customstringconvertible as well.

marandaneto avatar Oct 09 '23 15:10 marandaneto