Dictionary with CER_casted() has ambiguous overloads.
sl33k opened this issue · 2 comments
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
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!
Hey thanks for the answer. Just wanted to let you know that it worked perfectly.
Keep up the good work