saoudrizwan / Disk

Delightful framework for iOS to easily persist structs, images, and data
MIT License
3.08k stars 170 forks source link

Custom Encoder not getting passed #65

Closed vojtabohm closed 5 years ago

vojtabohm commented 5 years ago

When I want to pass encoder with custom nonConformingFloatEncodingStrategy to Disk.append, it will not get passed inside the function to the Disk.save function. The encoder parameter is there but it has a default value and is not overwritten.

I think this should be added.

vojtabohm commented 5 years ago
Screenshot 2019-04-07 at 11 47 05

The save function won't get the encoder parameter from the append function

saoudrizwan commented 5 years ago

Please try pod 'Disk', '~> 0.6.2' and let me know if that works for you. Thanks

vojtabohm commented 5 years ago

Although it seems like it is getting passed (I cannot debug it except visually) it still doesn't work. Still getting

"Unable to encode Float.nan directly in JSON. Use JSONEncoder.NonConformingFloatEncodingStrategy.convertToString to specify how the value should be encoded."

Which is what I wanted to prevent using a custom encoder that has this strategy and gets passed into Disk.

vojtabohm commented 5 years ago

I figured out what was wrong. When the encoder sees Float.NaN or Float.infinity it will convert it to "0" (my custom encoder that is being correctly passed now).

However when appending, the Disk library decodes the past data and tries to append the new data. The old data has "0" instead of a Float so that's why it failed.

If anyone ever stumbles upon this issue: Make sure to also pass custom Decoder with nonConformingFloatDecoding strategy! :D

Thank you saoudrizwan for fixing this issue!