UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 51: CupcakeCorner - JSON Decoder

Forums > 100 Days of SwiftUI

My project keeps failing when it tries to decode the JSON that is sent back. I would assume it's because whatever it's sending is wrong, but I can't figure out what exactlty I did wrong.

Project Link

2      

You forgot to encode your name property in Order.swift. Add the following line to the encode(to) function:

try container.encode(name, forKey: .name)

How I got to this point was I force try'd to make a decodedOrder, and saw the following in the debugger console:

2020-07-24 10:24:42.162521-0400 CupcakeCorner2[37594:2038623] Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "name", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"name\", intValue: nil) (\"name\").", underlyingError: nil)): file

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

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.