Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a JSONDecoder instance.
iOS Swift
let decoder = [1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using JSONEncoder instead of JSONDecoder.
Trying to instantiate Decoder which is a protocol.
✗ Incorrect
Use JSONDecoder() to create a decoder for JSON data.
2fill in blank
mediumComplete the code to set the date decoding strategy to ISO8601.
iOS Swift
decoder.dateDecodingStrategy = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .formatted without a date formatter.
Choosing .secondsSince1970 which expects a timestamp.
✗ Incorrect
Use .iso8601 to decode dates in ISO8601 format.
3fill in blank
hardFix the error in setting the key decoding strategy to convert from snake_case.
iOS Swift
decoder.keyDecodingStrategy = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .useDefaultKeys which does no conversion.
Trying .convertToCamelCase which does not exist.
✗ Incorrect
Use .convertFromSnakeCase to automatically convert snake_case keys to camelCase properties.
4fill in blank
hardFill both blanks to set the data decoding strategy to base64 and the non-conforming float decoding strategy to convert from string.
iOS Swift
decoder.dataDecodingStrategy = [1] decoder.nonConformingFloatDecodingStrategy = [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .deferredToData for data decoding which defers to Data's init.
Using .throw which causes decoding to fail on non-conforming floats.
✗ Incorrect
Use .base64 for data decoding and .convertFromString for non-conforming floats from strings.
5fill in blank
hardFill all three blanks to create a JSONDecoder, set the key decoding strategy to convert from snake_case, and set the date decoding strategy to seconds since 1970.
iOS Swift
let decoder = [1]() decoder.keyDecodingStrategy = [2] decoder.dateDecodingStrategy = [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using JSONEncoder instead of JSONDecoder.
Mixing up date decoding strategies.
✗ Incorrect
Create JSONDecoder(), set keyDecodingStrategy to .convertFromSnakeCase, and dateDecodingStrategy to .secondsSince1970.