DAY #32

Codable (Part 2 of 4)

If you just have a 1:1 conversion like snake_case->camelCase, you do not need to do what was described in day #31, instead you can use built in decoding strategies.

1
2
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase

There are options for DefaultKeys, SnakeCase, and Custom. This technique comes with a performance cost, but is great for prototyping.

Originally published 09/17/2021 @ https://pittcsc.org/ Discord

Published here on 09/09/2022. Blog published date reflects the original date of publication.