Skip to content

Remove useless Codable requirement #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arnauddorgans
Copy link

The PR removes useless Codable requirements

@bsneed
Copy link
Contributor

bsneed commented Jul 13, 2025

can you elaborate on why you needed to make this change, or was it purely for correctness?

@arnauddorgans
Copy link
Author

@bsneed it forces us to write useless Decodable conformances on objects that are not decodable
e.g.

extension AnalyticsClient {
    struct Context: Codable {
        let value: Any
        let encode: (inout SingleValueEncodingContainer) throws -> Void

        init<T: Encodable>(_ value: T) {
            self.value = value
            self.encode = { try $0.encode(value) }
        }

        init(from decoder: any Decoder) throws {
            // Waiting for https://github.com/segmentio/analytics-swift/pull/386 to me merged
            throw DecodingError.dataCorrupted(.init(
                codingPath: decoder.codingPath,
                debugDescription: "Decodable is not used"
            ))
        }

        func encode(to encoder: any Encoder) throws {
            var container = encoder.singleValueContainer()
            try encode(&container)
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants