Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Weather App Refactoring Using Codable Recap: Refactoring Using Codable

Christian A. Castro
Christian A. Castro
30,501 Points

Complete the blanks to make the nested enum a valid CodingKey conforming type!!! Help please!!!!

Any idea why is not taking the answer!?? The answer should be case model = "model"

import Foundation

struct Vehicle: Codable {
    let model: String

    enum CodingKeys: String, CodingKey 
 {
        case model = "model"
    }
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Christian A. Castro ! I thought that, too. In fact, I was stuck on this one question of this quiz for a while. Then I went out to the Apple Developer documentation here

And I found this:

If the keys used in your serialized data format don't match the property names from your data type, provide alternative keys by specifying String as the raw-value type for the CodingKeys enumeration. The string you use as a raw value for each enumeration case is the key name used during encoding and decoding. The association between the case name and its raw value lets you name your data structures according to the Swift API Design Guidelines rather than having to match the names, punctuation, and capitalization of the serialization format you're modeling.

Now, this might sound like a lot, but take a look at the example below that. You'll see that you're actually putting a bit too much information here.

It's not:

case model = "model"

It's just:

case model

Hope this helps! :sparkles:

Christian A. Castro
Christian A. Castro
30,501 Points

Jennifer Nordell Thank you so much!! I really appreciate the time you took to answer my question. Have a wonderful day, bless!! Thank you again!