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

Dictionary with CER_casted() has ambiguous overloads. #21

Closed
sl33k opened this issue Aug 29, 2016 · 2 comments
Closed

Dictionary with CER_casted() has ambiguous overloads. #21

sl33k opened this issue Aug 29, 2016 · 2 comments

Comments

@sl33k
Copy link

sl33k commented Aug 29, 2016

Hey,

i'm trying to encode a dictionary with variable value types. According to the Github Documentation one should cast the dictionary with .CER_casted() (since the value type is a protocol) before decoding/encoding. The decoding part works fine but for some reason i can't get the encoding to work.
The Dictionary is of the type:
[String: CerealType]

Its decoded like this:
guard let data:[String:CerealType] = try decoder.decode(dataKey)?.CER_casted() else { throw CodingError.MissingData } self.data = data

and encoded like this:

try encoder.encode(self.data.CER_casted(), forKey: dataKey);

which fails with:

Ambiguous Refrence to member 'encode(_:forKey:)

Any Ideas?

-- malte

@sl33k sl33k changed the title Dictionary with CER_casted() has ambigous overloads. Dictionary with CER_casted() has ambiguous overloads. Aug 29, 2016
@ketzusaka
Copy link
Contributor

Hey there,

If you're working with a protocol you'll need to use IdentifyingCerealType, and not CerealType. This is because the type needs to have an identity registered to Cereal for the lookup. You'll also need to use decoder.decodeIdentifyingCerealDictionary -- I had to do that because of the inheritance, which causes those ambiguous references.

Hope that helps, and sorry for the late response!

@sl33k
Copy link
Author

sl33k commented Aug 31, 2016

Hey thanks for the answer. Just wanted to let you know that it worked perfectly.
Keep up the good work 👍

@sl33k sl33k closed this as completed Aug 31, 2016
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

No branches or pull requests

2 participants