saoudrizwan / Disk

Easily persist structs, images, and data on iOS
MIT License
3.1k stars 170 forks source link

Encode & decode with not default dateEncodingStrategy #17

Closed nixzhu closed 6 years ago

nixzhu commented 6 years ago

I think we need to pass encoder & decoder if necessary. A pull request is here https://github.com/saoudrizwan/Disk/pull/16

saoudrizwan commented 6 years ago

Hey @nixzhu thanks for your PR!

I don't think adding this extra step is necessary for the sake of simplicity when using Disk for most use cases.

In your case, where you want to change some of the JSONEncoder's properties, like it's date coding strategy, I suggest you convert your Codable struct to Data first using your own JSONEncoder and then using Disk to save that data, Disk.save(data, to: .documents, as: "messages.json")

nixzhu commented 6 years ago

But there is append for Codable, in that case, data is not enough.

jyounus commented 6 years ago

nixzhu's PR allows users to pass a custom decoder/encoder or use the default one. So merging it shouldn't cause any issue to existing code. It would be great if it could be merged, it would keep things nice and simple, rather than converting into a Data object back and forth.