Skip to content
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

Proof of concept: Two types of decoders #2

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

Conversation

hello-im-szymon
Copy link
Collaborator

This allows for a bit less strict decoders. For example:

private struct ImageDecoder: ConcreteTypeDecoder {

    enum DecodingError: Error {
        case invalidData
    }

    func decode(_ data: Data) throws -> UIImage {
        guard let image = UIImage(data: data) else {
            throw DecodingError.invalidData
        }
        return image
    }

}

The API is not changed for existing clients.

// For legacy reasons
public typealias DataDecoder = AnyTypeDecoder

public protocol ConcreteTypeDecoder {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about the naming

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.

1 participant