0
0
iOS Swiftmobile~5 mins

Custom decoder configuration in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AdateEncodingStrategy
BkeyDecodingStrategy
CdataDecodingStrategy
DdateDecodingStrategy
What does the keyDecodingStrategy .convertFromSnakeCase do?
AIgnores key names during decoding
BConverts camelCase keys to snake_case
CConverts snake_case keys to camelCase
DConverts keys to uppercase
To decode nested JSON objects manually, which method do you use inside init(from decoder: Decoder)?
AnestedContainer(keyedBy:forKey:)
BdecodeNestedObject()
CdecodeIfPresent()
DcontainerForNested()
If your JSON date format is custom, how do you handle decoding?
AUse a custom DateFormatter and set it in dateDecodingStrategy
BUse default decoding only
CIgnore the date field
DConvert date to string manually after decoding
What is the purpose of implementing init(from decoder: Decoder) yourself?
ATo encode data manually
BTo customize how your type decodes data beyond automatic decoding
CTo create a new instance without decoding
DTo skip decoding
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.