Recall & Review
beginner
What is a custom decoder in Swift's Codable system?
A custom decoder lets you control how data is read and converted into your Swift types, especially when the default decoding doesn't fit your data format.
Click to reveal answer
beginner
Why would you use custom decoder configuration?
To handle special cases like date formats, key naming differences, or nested data structures that the default decoder can't handle automatically.
Click to reveal answer
intermediate
How do you customize the date decoding strategy in JSONDecoder?
You set the
dateDecodingStrategy property, for example: decoder.dateDecodingStrategy = .iso8601 to decode ISO 8601 date strings.Click to reveal answer
intermediate
What is the role of
keyDecodingStrategy in a decoder?It controls how keys from JSON map to your Swift property names, like converting snake_case keys to camelCase properties automatically.
Click to reveal answer
advanced
How can you decode nested JSON objects with a custom decoder?
By implementing
init(from decoder: Decoder) in your type and manually extracting nested containers using container.nestedContainer(keyedBy:forKey:).Click to reveal answer
Which property of JSONDecoder lets you change how date strings are decoded?
✗ Incorrect
The dateDecodingStrategy property controls how date strings are interpreted during decoding.
What does the keyDecodingStrategy .convertFromSnakeCase do?
✗ Incorrect
It automatically converts JSON keys written in snake_case to Swift property names in camelCase.
To decode nested JSON objects manually, which method do you use inside init(from decoder: Decoder)?
✗ Incorrect
nestedContainer(keyedBy:forKey:) lets you access nested JSON containers for manual decoding.
If your JSON date format is custom, how do you handle decoding?
✗ Incorrect
You create a DateFormatter matching your format and assign it to dateDecodingStrategy.custom.
What is the purpose of implementing init(from decoder: Decoder) yourself?
✗ Incorrect
Implementing init(from decoder: Decoder) lets you control decoding logic for complex or custom data.
Explain how you would configure a JSONDecoder to decode dates in a custom format and convert snake_case keys to camelCase properties.
Think about setting properties on JSONDecoder before decoding.
You got /3 concepts.
Describe the steps to decode a nested JSON object manually using a custom decoder in Swift.
Focus on how to access nested containers inside the decoder.
You got /4 concepts.