GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

JSONDecoder and absent optionals

Forums > Swift

Context: Using SwiftData with an explicitly Codable class containing an optional.

Task: Decoding json data which intentionally lacks the optional's key

Result is JSONDecode fails, complaining about the absent key and something nil

I thought the decoder would by default ignore missing keys.

How should I be thinking about this problem?

(Latest MacOS 14 and non-beta Xcode)

3      

Go further, faster with the Swift Career Accelerator.

GO FURTHER, FASTER Unleash your full potential as a Swift developer with the all-new Swift Career Accelerator: the most comprehensive, career-transforming learning resource ever created for iOS development. Whether you’re just starting out, looking to land your first job, or aiming to become a lead developer, this program offers everything you need to level up – from mastering Swift’s latest features to conquering interview questions and building robust portfolios.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.