You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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
The text was updated successfully, but these errors were encountered: