-
Notifications
You must be signed in to change notification settings - Fork 7
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
Error when use Codable in class inheritance #24
Comments
I was able to solve this problem this way. First I added the auxiliary protocol.
Then
And then just remove |
Interesting. So your goal is to encode values into the same keyed container in both the Superclass and the Subclass? When I implemented the logic, it seemed reasonable to only one call to a container (single, keyed, or unkeyed).
|
Hi Christoph. Yes, that’s true and it’s not an easy task. I did something similar a long time ago, but only for a specialized data format and it’s already difficult for me to remember exactly how it all works. I'll give some code snippets, maybe it will help you somehow. But probably the main idea is to store data by reference and then
And one more thing, decoding with inheritance also did not work correctly. And thank you for your work and such a cool package. This should be part of the standard library someday 🙂 |
Thanks for the input. You mentioned that decoding with inheritance didn't work, do you have an example? |
Thank you for your answer. How great it would be if we all had more free time 🙂 You're right that this is a borderline case and it's not urgent, you already did a great job. When I was preparing an example for you, I noticed something - if you do not use the custom
As you can see through |
Thanks for the example. It looks like the root cause for the inheritance issue is the same, where it was previously not possible to call It wasn't actually that difficult. I simply extracted the encoded data storage to separate classes and simply return wrapper structs to it. Thanks for bringing this issue to my attention. |
Hi Christoph. I tested it on my code and everything works fine, thank you very much 🙂 |
I'm trying to use this wonderful library in a class that inherits from the base Codable class.
And the error appears
Multiple calls to container(keyedBy:), unkeyedContainer(), or singleValueContainer()
The text was updated successfully, but these errors were encountered: