0
0
iOS Swiftmobile~10 mins

Custom decoder configuration in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a JSONDecoder instance.

iOS Swift
let decoder = [1]()
Drag options to blanks, or click blank then click option'
ADecoderConfig
BDecoder
CJSONEncoder
DJSONDecoder
Attempts:
3 left
💡 Hint
Common Mistakes
Using JSONEncoder instead of JSONDecoder.
Trying to instantiate Decoder which is a protocol.
2fill in blank
medium

Complete 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'
A.formatted
B.iso8601
C.deferredToDate
D.secondsSince1970
Attempts:
3 left
💡 Hint
Common Mistakes
Using .formatted without a date formatter.
Choosing .secondsSince1970 which expects a timestamp.
3fill in blank
hard

Fix 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'
A.convertFromSnakeCase
B.useDefaultKeys
C.custom
D.convertToCamelCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using .useDefaultKeys which does no conversion.
Trying .convertToCamelCase which does not exist.
4fill in blank
hard

Fill 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'
A.base64
B.convertFromString
C.deferredToData
D.throw
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.
5fill in blank
hard

Fill 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'
AJSONDecoder
B.convertFromSnakeCase
C.secondsSince1970
D.iso8601
Attempts:
3 left
💡 Hint
Common Mistakes
Using JSONEncoder instead of JSONDecoder.
Mixing up date decoding strategies.